Re:Object-oriented design patterns in C and kernel development
by chunkyguy on Wednesday August 27, 2025 @02:01PM
(#45042898)
> 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-...
Re:Object-oriented design patterns in C and kernel development
by 1718627440 on Wednesday August 27, 2025 @01:52PM
(#45042756)
When 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.
Re:Object-oriented design patterns in C and kernel development
by frutiger on Thursday August 28, 2025 @07:01AM
(#45050686)
A SIGSEGV is not guaranteed when calling an address that does not have a function.
Re:Object-oriented design patterns in C and kernel development
by 1718627440 on Thursday August 28, 2025 @12:10PM
(#45053924)
Are 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.
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.