[Top][All Lists]
[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
- ObjectiveC accessors,
Stefan Urbanek <=
- Re: ObjectiveC accessors, David Ayers, 2004/05/30
- Re: ObjectiveC accessors, Stefan Urbanek, 2004/05/30
- Re: ObjectiveC accessors, David Ayers, 2004/05/30
- GC ( Was: Re: ObjectiveC accessors), Stefan Urbanek, 2004/05/30
- Re: GC ( Was: Re: ObjectiveC accessors), David Ayers, 2004/05/30
- Re: GC ( Was: Re: ObjectiveC accessors), Helge Hess, 2004/05/30
- Re: GC ( Was: Re: ObjectiveC accessors), Public Look, 2004/05/30
- Re: ObjectiveC accessors, Marcel Weiher, 2004/05/31
- Re: ObjectiveC accessors, Helge Hess, 2004/05/31
- Re: ObjectiveC accessors, Marcel Weiher, 2004/05/31