Hacker News new | ask | show | jobs
by pianoben 1646 days ago
If anything, the old syntax was pure and consistent with what actually happens - message sending. Dot notation muddies the waters, IMO, but certainly is convenient. Ditto the collection literals.
1 comments

I still say they did properties wrong. If you have a property prop, it should synthesize methods prop and prop: and expose them to the user. Then, to get you say [obj prop] and to set you say [obj prop: newVal]. This is a convention widely used in Smalltalk, and is nearly as convenient to use as dot notation. Dot notation in Objective-C makes the dot operator mean two different things; and in one case it takes a bare struct and in the other case it takes a pointer. Utterly weird. But it's a belt onion: done because it was the style at the time.
This is in fact how @property works; the declaration is sugar for a pair of accessor methods. The dot syntax is sugar for calling those methods.

    #include <Foundation/Foundation.h>

    @interface Foo : NSObject
    @property (copy) NSString *bar;
    @end

    @implementation Foo
    @end

    int main(int argc, char *argv[]) {
        Foo *foo = [Foo new];
        [foo setBar:@"Hello, world!"];
        NSLog(@"%@", [foo bar]);
        return 0;
    }
The dot syntax makes it difficult to parse whether you are dealing with a C struct or an Objective-C object.

Objective-C was grafted onto C with very clear demarcation lines.

We don’t mind being able to declare a property with `@property`. We do mind that they introduced dot syntax

Same here, I was never a proponent of the dot syntax. As we know, compiler development at Apple got taken over at some point by C++ people, and we can all see the results: https://blog.metaobject.com/2014/06/remove-features-for-grea...
t.rotate (a, v); // Original

t rotate (a, v); // Who needs dot?

t rotate a, v; // Who needs brackets?

t rotate by: a around: v; // Who needs ambiguity?

t rotateBy: a around: v // This is Smalltalk

I’m rolling — this is perfect.

Civilization has used dot notation in basically all thought, as evidenced by pretty much any nation’s laws / code

Which of course means it's in no way ambiguous or overly used. One syntax for one purpose. Until dot notation was used for @property you never had to guess if you were looking at a structure or at a class. See how that works?