Home > Archive > Objective C > March 2005 > no instance variables with or without braces
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
no instance variables with or without braces
|
|
| Dan Hitt 2005-03-16, 4:06 pm |
| What is the difference between defining a class with no instances
variables but having empty braces, and one which has no instance
variables and no braces?
For example:
Class A interface:
#import <objc/Object.h>
@interface A_Class:Object {
}
@end
Class B interface:
#import <objc/Object.h>
@interface B_Class:Object
@end
The B form seems to be preferred in the Foundation headers on OS X.
Further, the B form seems to be associated with class clusters, but
there doesn't seem to be any particular reason why the B form should be
more abstract than the A form.
Thanks in advance for any info, advice, corrections, etc.
dan
| |
| Michael Ash 2005-03-16, 4:06 pm |
| Dan Hitt <hitt@eskimo.com> wrote:
> What is the difference between defining a class with no instances
> variables but having empty braces, and one which has no instance
> variables and no braces?
[snip]
As far as the compiler cares, there is no difference whatsoever. From a
technical standpoint, it doesn't matter.
From a style point of view, it might matter. You could argue that an empty
set of braces says "we might add things later if we want to", whereas no
braces at all says "this will always be empty". Of course, given the
realities of binary compatibility and ObjC's version of the fragile base
class problem, the prospects of Apple adding something later are slim.
| |
| Sherm Pendley 2005-03-16, 4:06 pm |
| Michael Ash wrote:
> From a style point of view, it might matter. You could argue that an empty
> set of braces says "we might add things later if we want to", whereas no
> braces at all says "this will always be empty".
You could also argue that it says "Instance variables are none of your
business. Use accessors." ;-)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
| |
| Michael Ash 2005-03-16, 4:06 pm |
| Sherm Pendley <spamtrap@dot-app.org> wrote:
> Michael Ash wrote:
>
>
> You could also argue that it says "Instance variables are none of your
> business. Use accessors." ;-)
Nice idea, but I don't think it'll fly. For one, it's difficult (but not
impossible) to convince the compiler that you want instance variables
after you told it that you didn't want any. And more importantly, such a
class would be very difficult to subclass without a great deal of mayhem,
random crashes, cats and dogs living together, etc. Since instance
variable layout is determined at compile time, the ivars really need to be
in the header for subclasses to work properly.
|
|
|
|
|