3 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. This introduces perfo
by 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-...
- pjmlp 1y agoIn NeXTSTEP it was fast enough to have the whole OS, including device drivers, written in Objective-C. In Smalltalk systems that stop being an issue after JITs got introduced.