gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ObjectiveC accessors


From: Stefan Urbanek
Subject: ObjectiveC accessors
Date: Sun, 30 May 2004 11:56:42 +0200

Hi,

While working on a quite large project I found myself writing lots of code that 
can be automaticaly generated. Among that code were lots of accessor (simlpe 
getter and setter) methods. It is quite common to write accessors for public 
instance variables and in most of the cases, the accessors are simple 
assignments or they just return an instance variable.

I was thinking about some decent inclusion of accessors in the ObjectiveC while 
maintaining language simplicity. After many attempts, through various @accessor 
and @getter I came with following simple and extensible language syntax:

@interface MyClass:NSObject
{
    NSString *name : public retained;
    NSArray  *collection : public readonly;
    NSString *weakReference : public nonretained;
}
- someInstanceMethod;
@end

So the syntax is:
@interface ...
{
        <ivar> : <keyword list>
}

where keyword list is space separated list of ivar attributes. The keywords 
used are just examples, feel free to imagine others that can be more 
appropriate. Meaning of the above keywords is:
"public" - automaticaly generate getter and setter methods for the ivar 
-[MyClass ivarName] and -[MyClass setIvarName:]
"retained" - use [ivar retain] in the setter method
"nonretained" - do not use [ivar retain] in the setter method (one of the two 
retained and nonretained should be default)
"readonly" - do not generate the setter method

Advantage of this syntax is, that it is extensible for other future attributes. 
Perhaps some custom keywords can be there to give more information (metadata) 
about ivars...

I want to keep the language as simple as possible, on the other hand, I think that frequently repeated patters should 
be simplified and incorporated into the language to simplify readability and maintainability of a source code. What I 
propose is to call "A device that computes" a "computer" and to say "Google it" instead 
of "Search it on a Google search engine" :-) In other words, introduce a single word instead of more complex 
phrase into the language.

What do you think?

Stefan Urbanek
--
http://stefan.agentfarms.net

First they ignore you, then they laugh at you, then they fight you, then you 
win.
- Mahatma Gandhi






reply via email to

[Prev in Thread] Current Thread [Next in Thread]