←back to thread

107 points wmlive | 2 comments | | HN request time: 0.001s | 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. bunderbunder ◴[] No.42137340[source]
This is another example of where you've got to read Wikipedia with a skeptical eye. That one in-passing mention of Java is incorrect. I don't know why it's in there, WikiBlame indicates that it's been there since 2004, which was the early days of Wikipedia when it was particularly unreliable.

So, the gist of the difference is this: object-oriented programming is, at its core, about late binding. Specifically, delaying decisions about what code will run when until run-time. But there's still some wiggle room to decide how late certain decisions are made. Most mainstream object-oriented languages like Java and C# more-or-less wait until the start of run-time to decide, but at that point the mapping from argument type to which code is run is pretty much settled. (This isn't necessarily 100% true, but it's the general rule.)

In a system that uses message passing, it's pushed even later, to method invocation time. Basically, each object (actor, whatever) gets to decide what code will be executed to handle a message every time it receives a new message, even for messages of the same type. In practice, most the time it's always the same code. But the point is that this level of dynamicism is a first-class language feature and not just a thing you can accomplish with hacks.

replies(1): >>42145739 #
2. em-bee ◴[] No.42145739[source]
i understand your explanation, but i still don't see how i am supposed to tell the difference as a programmer. to be a first class language feature it has to be something the programmer can see and use consciously. the only feature there is the ability to have catchall methods, but while the existence of such a feature is an indication that very late binding happens, the absence of it does not indicate otherwise. so it goes back to pretty much all dynamic languages with a runtime probably use message passing because they either do have such a feature or could have it. but i don't see that claim supported anywhere. everyone just seems to talk about how smalltalk is somehow different, but i can't see how it is different from javascript, php, pike or other dynamic languages.

and i believe what you say about java and wikipedia. it just shows again that the distinction is not obvious.

i found this discussion on stackexchange: https://softwareengineering.stackexchange.com/questions/3352...

but reading that doesn't help me to tell the distinction between java and smalltalk either. the point appears to be that all OO is message passing, and the only distinction as far as i can tell is that java doesn't have extreme late-binding of all things, but that is something i can't know just by looking at the language. it's a hidden implementation detail. not being able to tell how the message is processed is another feature that message passing is supposed to have, btw.

the stackexchange answer however also shows why i am not seeing any revelation when using smalltalk. if all OO is supposed to be message passing then it's no wonder, it all looks the same to me.

note that i don't want to argue either way. i don't know enough about this to make any kind of argument. and i am trying to figure out the right questions to ask so i can learn and understand more. your comment did help me move forward at least. thanks.