5 ms·
They're function calls right? I can't square the "message passing" conceit (implying putting message objects on queues, dequeuing etc) with the claim that Obj-C
by nmeofthestate 7mo ago
They're function calls right? I can't square the "message passing" conceit (implying putting message objects on queues, dequeuing etc) with the claim that Obj-C is just C with some extra stuff.
- pavlov 7mo agoThey're not direct function calls, but sugar for objc_msgSend(): https://developer.apple.com/documentation/ObjectiveC/objc_msgSend https://developer.apple.com/documentation/ObjectiveC/objc_ms...
- 9rx 7mo agoAbsolutely not. It only sends a message. The receiver doesn't have to have a corresponding method and can do with that message what it will. Objective-C is a 'true' object-oriented language, like Smalltalk.
- chuckadams 7mo ago> a 'true' OOP language, like Smalltalk. I guess Simula, which is older than Smalltalk, doesn't get a say.
- 9rx 7mo agoWhat would it have to say about it? When "object-oriented" was first told, it was said that what defines it is message passing. Simula does not have message passing. It uses function calling. Simula does have objects, but having objects does not imply orientation.
- flohofwoe 7mo agoIn the end though most of those 'sending a message' actions are just fancy virtual method calls (e.g. an indirect jump), everything else would be much too slow: https://www.mikeash.com/pyblog/friday-qa-2017-06-30-dissecting-objc_msgsend-on-arm64.html https://www.mikeash.com/pyblog/friday-qa-2017-06-30-dissecti... IMHO the whole 'message' and 'sending' lingo should be abandondend, the job of objc_msgSend is to look up a function pointer by certain rules. There are no 'messages' involved, and nothing is 'sent'.
- 9rx 7mo ago> There are no 'messages' involved, and nothing is 'sent'. The conceptual difference is significant as an object can respond to messages that it doesn't have a method for. You are, conceptually, just sending a message and leave it up to the object what it wants to do with it (e.g. forwardInvocation:). That is, after all, what sets "object-oriented" apart from having objects alone. Optimizations that can be made under the hood don't really affect the language itself.
- flohofwoe 7mo ago> can respond to messages that it doesn't have a method for. Clang produces a warning in that case though (something along the lines of "object might not respond to ..."), I don't think that feature is particularly useful in practice (also because it kills any sort of type safety) :)
- 9rx 7mo agoIt was incredibly useful in the olden days. The NeXT/Apple ecosystem leaned on it heavily. We have new ways to approach problems nowadays, so it may be fair to say that object-oriented programming is a relic of the past. I mean, it is telling that Smalltalk, Objective-C, and Ruby are the only languages to ever go down that road. Still, if you are using an OO language, then it makes sense to lean into OO features. Otherwise, why not use a language better suited to your problem?
- kccqzy 7mo agoAnd the reason it’s a warning and not an error (like in C++) is that it’s actually possible that the object can respond to such a message but the compiler doesn’t know about it.
- MaxBarraclough 7mo ago> That is, after all, what sets "object-oriented" apart from having objects alone. I wouldn't say so, most object-oriented languages don't work like Objective-C/Smalltalk. Today, I think most programmers would agree that inheritance is the defining feature of object-orientation.