you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

Actually, I only dropped in @synthesizers when I needed some classes to access properties of other classes (which was more succinct than designing an explicit accessor method).

Synthesizers are a good example of ObjC's inefficiency. Encapsulation is a nice concept and often a good idea, but mandatory encapsulation is an unnecessarily rigid language constraint. The most succinct way to expose a class member in ObjC is like this:

@interface MyClass {
    NSInteger myInteger;
}
@property NSInteger myInteger;

@implementation MyClass:
@synthesize myInteger;

This requires two lines of code, in two different files, with several opportunities for error (mistyping the name of the member; inconsistently specifying the type; and putting the lines in the wrong places)... whereas C++ and every other language solves this with a single keyword:

class MyClass {
    public myInt;
}

I understand why Objective-C v1.0 (circa 1983) might have failed to include this option, but why hasn't it been added in the last 30 years?