←back to thread

107 points wmlive | 4 comments | | HN request time: 0.426s | source
Show context
itslennysfault ◴[] No.42129253[source]
So, this is why the abomination that is Obj-C is/was used for iPhone/Mac apps. I can't overstate how much I hate Obj-C. I'm so sooo happy Swift has pretty much entirely taken over.

Side note... I feel similarly about the Java to Kotlin transition. Sooo much better. Although, I don't hate Java NEARLY as much as Obj-C.

replies(5): >>42129327 #>>42129817 #>>42130011 #>>42130250 #>>42130804 #
ramesh31 ◴[] No.42129327[source]
To each their own. I'm convinced it's just a visceral reaction to the square bracket syntax. Obj-C remains my favorite language of all time (although I haven't written it in years). Having a high level language that allows you to seamlessly drop into C felt like magic.
replies(5): >>42129520 #>>42129543 #>>42129839 #>>42130389 #>>42130417 #
itslennysfault ◴[] No.42129839[source]
Interesting, I guess that part was missed on me since I only really ever used it for iPhone apps and never really had a need to use C directly.

Also, you're 100% right. The square brackets are what immediately repulsed me and continued to befuddle me even after years of experience with it. Also, everything just feels "backwards" to me if that makes any sense. Coming from Java/C#/JavaScript everything just seemed unintuitive to me at all times. Also, I think this was heavily compounded by using xCode which (at the time) was incredibly laggy. So, I'd mess up the Obj-C syntax and the IDE wouldn't tell me for what felt like forever. Often I'd make a change and hit "play" before the syntax highlighting caught up and that always felt infuriating.

I last used xCode about 4 years ago and it was still an issue then (even with swift).

replies(3): >>42130086 #>>42130409 #>>42131134 #
ramesh31 ◴[] No.42130086[source]
>"Also, everything just feels "backwards" to me if that makes any sense."

Because it is. Obj-C comes from the Smalltalk lineage by way of Alan Kay, using message passing [0] versus method invocation. It's a subtle difference with huge implications to how you design systems. Method invocation won out mostly because of Java and C++, but there was a time it wasn't clear which was the better OO paradigm.

[0] https://en.m.wikipedia.org/wiki/Message_passing

replies(3): >>42130432 #>>42130874 #>>42132104 #
em-bee ◴[] No.42132104[source]
i have learned smalltalk, common lisp, java, python, ruby, perl, php, C, javacript and a few other languages, and i still do not understand the difference between message passing and function invocation. they look the same to me. according to wikipedia the difference is

"In contrast to the traditional technique of calling a program by name, message passing uses an object model to distinguish the general function from the specific implementations. The invoking program sends a message and relies on the object to select and execute the appropriate code."

Method invocation won out mostly because of Java and C++

but according to the wikipedia article java uses message passing.

supposedly the distinction is that i can have a generic method that gets called if a named method can not be found. in smalltalk that's doesNotUnderstand: in ruby it's method_missing. javascript used to have __noSuchMethod__, in php i can overload __call, in pike i do the same with defining a method called `(), and many more.

so are they all using message passing? and then if java is supposed to use message passing and javascript removed __noSuchMethod__ it seems that alone can't be the distinction.

if there is a distinction at all then it look more like an implementation detail that does not actually affect what kind of code you can write, and more importantly, based on that it is not at all clear that method invocation won out.

replies(3): >>42132608 #>>42133455 #>>42137340 #
1. astrange ◴[] No.42132608[source]
The difference is NSInvocation. A function pointer doesn't capture the arguments to the function, but a message does.

Also, you can change the destination of a message send at runtime, but you can't change the destination of a function call unless you're dtrace and can do code patching.

replies(1): >>42132712 #
2. em-bee ◴[] No.42132712[source]
ok, so that means message passing needs a runtime, and it can be assumed that pretty much every language that has a runtime uses message passing. more evidence that it is message passing that won out.

and the profound enlightenment ( https://news.ycombinator.com/item?id=42130432 ) is not specific to message passing but about a dynamic language runtime. being able to intercept messages/function calls is just one of the benefits of that.

replies(1): >>42133600 #
3. astrange ◴[] No.42133600[source]
Not sure if objc_msgSend is a runtime, but it does require malloc, so there are limits to how low level it can be.
replies(1): >>42170568 #
4. mpweiher ◴[] No.42170568{3}[source]
> objc_msgSend [...] does require malloc,

Are you sure about that?

    ]pwd
    objc4/runtime/Messengers.subproj
    ]rg malloc
    ]
The two variants I implemented way back when also did not require malloc.

And of course NeXT used objc_msgSend() in the kernel, to good effect, so that's pretty low-level.