4 ms·
In Smalltalk and Objective-C, you just check at runtime whether an object instance responds to a message. This is the original OOP way. It's sad that OOP was c
by pavlov 1y ago
In Smalltalk and Objective-C, you just check at runtime whether an object instance responds to a message. This is the original OOP way.
It's sad that OOP was corrupted by the excessively class-centric C++ and Java design patterns.
- mettamage 1y agoWait, so in obj-c, could you also write some kijdnof doesnotunderstand method to achieve some dynamic method dispatch?
- pjmlp 1y agoYes, that is how microservices were implemented in the days of NeXTSTEP. with PDO. https://en.wikipedia.org/wiki/Portable_Distributed_Objects https://en.wikipedia.org/wiki/Portable_Distributed_Objects
- mettamage 1y agoSo why did Swift become a thing? Or does Swift has this too?
- bitwize 1y agoBecause Objective-C does not have foo.bar() style method calls and that's what everybody else uses and wants.
- saagarjha 1y agoBecause Swift adds many other features.
- astrange 1y agoSwift isn't messaging-based, it's protocol-based. (Except it's also messaging-based if you use @objc.)
- pjmlp 1y agoBecause Objective-C being based on C, means it would never be safe while remaining compatible with C. Also dynamic runtime dispatch Smalltalk style can never be as fast as the VMT based dispatch, or compile time dispatch via generics, even with all the optimizations in place, that objc_msgSend() has had during its lifetime. Still, Metal is implemented in Objective-C, so there is that.
- 1718627440 1y agoObjective-C already has a different compiler I fail to see how the compiler is restricted in the checks it does.
- ryao 1y agoThere is always a subset of the population for which it is fashionable to try to make a new language to make things easier. It is inevitable that someone in a sufficiently large organization will try to make one, provided management supports it. Apple is a very wealthy company that is happy to sponsor R&D, had someone interested in this that they sponsored and the result was appealing enough that they decided to adopt it. That is my understanding of how the process generally works and what I am willing to guess happened. Prior to this, they had been making incremental changes to Objective-C. That said, from what I have seen of the syntax of both languages, swift’s syntax is nicer and that is not something that they would have been able to get from Objective-C. They already had tried syntax reform for Objective-C once in the past and abandoned it.
- astrange 1y agoIt's how many things are implemented, like UI message routing, IPC, undo, test mocks.
- pjmlp 1y agoActually I would say that it is sad that developers learn a specific way how a technology is done in language XYZ and then use it as template everywhere else, what happened to the curiosity of learning?
- ryao 1y agoThe curiosity of learning is infeasible given that there are >15,000 programming languages. You might say to only learn the major/influential languages, but I have found my curiosity to wane with every additional language that I learn. So far, I have either used or dabbled in C, C++, FORTRAN, SML/NJ, PHP, Java, JavaScript, Python, Go, POSIX Shell, Assembly and SQL stored procedures. That is not to mention different dialects/versions of those, and the fact that assembly itself is a catch all category in which I have dabbled in multiple languages too. I am also not including languages for which I spent a minuscule amount of time (say a few hours), such as D (as in DTrace), Objective-C, Perl, COBOL and LISP. Then there is the misadventure into C# I took before I actually understood programming where I got stuck and dropped it. I am also not sure if I should mention AWK, as I only use it to select the Nth field in a bunch of lines of text when doing shell scripting and nothing else. Thus, I have used it many times, yet know almost none of its syntax. Every few years, someone tells me I should learn another language, and in recent years, there just is no desire in my mind to want to learn yet another language that is merely another way of doing something that I already can do elsewhere and the only way I will is if I am forced (that is how I used Go). That said, I do see what you are saying. C++ for example has an “support every paradigm” philosophy, so whenever someone who has learned C++ encounters a language using a paradigm that C++ assimilated, there is a huge temptation to try to view it through the lens of C++. I also can see the other side too: “C++ took me forever to learn. Why go through that again when I can use C++ as a shortcut to understand something else?”. C++ is essentially the Borg of programming languages.
- 1718627440 1y agoHow do you got proficient in so many languages? I think it takes some years, before you start to think in a language.
- bluGill 1y agoJava is excessively class centric. C++ often is, but it need not be and developers are movingiaway. smalltalk is not original OO - c++ took oo from simula which was always a different system.
- moregrist 1y ago> In Smalltalk and Objective-C, you just check at runtime whether an object instance responds to a message. This is the original OOP way. This introduces performance issues larger than the typical ones associated with vtable lookups. Not all domains can afford this today and even fewer in the 80s/90s when these languages were first designed. > It's sad that OOP was corrupted by the excessively class-centric C++ and Java design patterns. Both Smalltalk and Objective-C are class based and messages are single-receiver dispatched. So it’s not classes that you’re objecting to. It’s compile-time resolved (eg: vtable) method dispatch vs a more dynamic dispatch with messages. Ruby, Python, and Javascript all allow for last-resort attribute/message dispatching in various ways: Ruby via `method_missing`, Python by supplying `__getattr__`, and Javascript via Proxy objects.
- 1718627440 1y agoWhen you fear about the branch miss, then you can also just call the method and catch the SIGSEGV. I think if you allow for the possibility of there being no implementation, then you can't really not have some decision there. This would also apply for say a C++ virtual method.
- frutiger 1y agoA SIGSEGV is not guaranteed when calling an address that does not have a function.
- 1718627440 1y agoAre you talking about C? In C it's not guaranteed whether a non existing function will result in an actual function call. As soon as an actual function call was generated by the compiler, a modern CPU is very likely to trap. We are talking about an optimization of a language implementation here. This would be very much written in a ASM or another language were this is defined.
- chunkyguy 1y ago> This introduces performance issues larger than the typical ones associated with vtable lookups. Don't know about other programming languages but with Objective-C due to IMP caching the performance is close to C++ vtable Name Iterations Total time (sec) Time per (ns) C++ virtual method call 1000000000 1.5 1.5 IMP-cached message send 1000000000 1.6 1.6 https://mikeash.com/pyblog/friday-qa-2016-04-15-performance-comparisons-of-common-operations-2016-edition.html https://mikeash.com/pyblog/friday-qa-2016-04-15-performance-...
- MangoToupe 1y agoSure, but that is a a horrible coding pattern. Even good smalltalk code doesn't rely on this. It's dogshit and lazy
- baranul 1y agoThis is a very good point. A greater distinction needs to be made about class-based versus class-free OOP. Many of the problems or constraints around OOP that people don't like, come back to classes. Often class-based programming is confused as being the only style of OOP, superior to all other styles, or heavy-handedly pushed on others. Many programmers are perfectly fine with using objects or only specific features of OOP, without classes, if they are "allowed" to.