News for hackers. Stuff that matters.
Re:Can you use a class in C? by rezonant on Sunday August 13, 2023 @08:17AM (#37109238)
Alan Kay isn't going to agree that you should simply pass structures around and use element-level procedures. Message passing as a concept is a higher order version of what you see in C++, not what you see in C. A big reason Kay dislikes C++ is because it doesn't go far enough in terms of dynamic dispatch and the ability to substitute implementations dynamically at runtime. One way to put it is: C++ makes decisions at compile time that should be made at runtime.

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.

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.

[1] https://en.wikipedia.org/wiki/C%2B%2B

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.