by drnick1 · 1y ago · 0 comments
It shows that C++ was considered too complex already in the 90s.
I can write this simple struct:
struct Person {
std::string name;
my_complicated_date_type date_of_birth;
};
and get serialization, network interop, logging, automated UI generation, hashing, type-safe IDs, etc. without having to write an additional line of code. Twenty years ago you had to write 2000 lines of additional boilerplate for each data type to get to the same place.Arguably the result would have been easier to read and maintain and not as slow to compile.
The problem with C++ is that you end up having to take most of its features into account, one way or the other, and it quickly gets complicated; at least that's my experience and the experience of many others.
But it's important to see the 1994 (and 1998) view of the world to understand how modern c++ features work. Because they start from that worldview and start adding convenient stuff. If you don't understand how c++ used to work, you may be confused with why c++ lambdas look so weird.
That may be the case, but there are plenty of examples of elegant implementations.
JUCE, for instance:
#include <juce_core/juce_core.h>
class MyComponent {
public:
void doAsyncOperation(std::function<void(int)> callback) {
// Simulate async work
juce::MessageManager::callAsync([callback]() {
callback(42); // Call the functor with result
});
}
};
// Usage
MyComponent comp;
comp.doAsyncOperation([](int result) {
juce::Logger::writeToLog("Callback received with: " + juce::String(result));
});
.. I think that's kind of clean and readable, but ymmv, I guess?Then we've got a "member function" where magically if we specify a function while midway through specifying a data structure the function is somehow treated as though it were part of that data structure - but of course it is actually just sugar. I know this confuses real learners.
And sure, the lambda syntax is awful but that's sort of par for the course by the time you reach it.
You generally don’t get to pick what parts other people want to use, which means that in the end you still have to deal with the entirety of the language.
Even when working alone, the complexity gradually creeps up on you.
Because it's all made to work together, start pulling anywhere and before you know it you're using another feature, and another, and so on.
And many features interact in exotic and hard to predict ways, so hard that entire careers have been spent on trying and failing to master the language.
Boom.
Now you are not only using the functional part of C++, but also in a nonstandard way! Merci Gilles. :)