Re:Can you use a class in C?
by chadcmulligan on Sunday August 13, 2023 @08:42AM
(#37109423)
Indeed, and C++ was initially a preprocessor (CFront) by Stroustrup, dynamic dispatch was considered too slow at the time, so c++ style objects and methods were faster and as a faster version of simula [1]. Objective C was an alternative that used something closer to smalltalk but it was slower and a few years later. C++ was first released in 1983 internally at AT&T, and for perspective, the 286 was released around the same time with a clock speed of 8 MHz.
Re:Can you use a class in C?
by up2isomorphism on Monday August 14, 2023 @03:24AM
(#37118363)
What he has said applies to any member functions. It is a nuance to have to add a parameter, but certainly it does not only apply to getter and setters.
Dynamic dispatchinga are not necessarily evil, but that also doesn’t exclude C. Not sure how this idea C++ is inherently more dynamic or static comes from. For a ling time you can implement all the dynamic behavior of C++ in C, and it took C++ ‘s template as expressive as C macros.
Sometimes, less is more.that’s where C++ never gets right.
What you are saying certainly applies neatly to getters and setters, but consider that classes are used for far more complex use cases than as a simple data holder. Indeed, if all you need is to store two integer components, you might not need a class.
Of course, in Smalltalk and it's ilk, you only have objects. So there is no opportunity to access data from within a structure (externally) without passing messages.