gnustep-dev
[Top][All Lists]
Advanced

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

Re: ObjectiveC accessors


From: David Ayers
Subject: Re: ObjectiveC accessors
Date: Sun, 30 May 2004 12:04:19 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040514

Stefan Urbanek wrote:
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?

Well actually the "retain/release/autorelease" paradigm is outside of the scope of the ObjC language. It's a part of the OpenStep specification and it's derivatives. There are however various macro based approaches to this issue. Maybe a semi "standardized" set of such macros could be a future feature of OpenStep derivatives.

Cheers,
David




reply via email to

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