C++ was so much cleaner in the 90s, when it was still essentially "C with classes," which is how I like to use the language. Modern standards have turned it into an ugly mess.
A sentence from the article: "Given the extreme undesirability of any new language features I'd hardly propose bound-pointers now." It shows that C++ was considered too complex already in the 90s.
Callbacks in C++ using template functors (1994)
21–30 of 51 posts
Re: Callbacks in C++ using template functors (1994)
#22Red flags for me when I see nonstandard functors in a c++ codebase (esp if the "glue" is in a setup function independent of the objects): (i) Have they thought about the relative lifetimes of the sender and receiver? (ii) Is the callback a "critical section" where certain side-effects have undefined behavior? (iii) Does the functors store debugging info that .natvis can use? (iv) Is it reeeeeeeally that bad to just i…
Even if it's 1994???
Re: Callbacks in C++ using template functors (1994)
#23Re: Callbacks in C++ using template functors (1994)
#24Earlier quoted context omitted.
A sentence from the article: "Given the extreme undesirability of any new language features I'd hardly propose bound-pointers now." It shows that C++ was considered too complex already in the 90s.
And then they introduced coke at committee meetings, the crazy shit they've been coming up with lately shows absolutely zero understanding of the complexity issue.
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.Re: Callbacks in C++ using template functors (1994)
#25Earlier quoted context omitted.
And then they introduced coke at committee meetings, the crazy shit they've been coming up with lately shows absolutely zero understanding of the complexity issue.
and yet client code can be incredibly simpler nowadays thanks to all these features. 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…
Arguably the result would have been easier to read and maintain and not as slow to compile.
Re: Callbacks in C++ using template functors (1994)
#26Red flags for me when I see nonstandard functors in a c++ codebase (esp if the "glue" is in a setup function independent of the objects): (i) Have they thought about the relative lifetimes of the sender and receiver? (ii) Is the callback a "critical section" where certain side-effects have undefined behavior? (iii) Does the functors store debugging info that .natvis can use? (iv) Is it reeeeeeeally that bad to just i…
> Red flags for me when I see nonstandard functors in a c++ codebase Even if it's 1994???
Re: Callbacks in C++ using template functors (1994)
#27C++ was so much cleaner in the 90s, when it was still essentially "C with classes," which is how I like to use the language. Modern standards have turned it into an ugly mess.
>ugly mess That may be the case, but there are plenty of examples of elegant implementations. JUCE, for instance: #include class MyComponent { public: void doAsyncOperation(std::function 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("Call…
Re: Callbacks in C++ using template functors (1994)
#28Re: Callbacks in C++ using template functors (1994)
#29Doing this today I'd just have a std::function parameter and have callers pass in a lambda. I may use a third party std::function that doesn't have the weird copy semantics though
Note that C++23 brings std::move_only_function if you're storing a callback for later use, as well as std::function_ref if you don't need lifetime extension.
https://en.cppreference.com/w/cpp/utility/functional/move_on...
Re: Callbacks in C++ using template functors (1994)
#30Earlier quoted context omitted.
And then they introduced coke at committee meetings, the crazy shit they've been coming up with lately shows absolutely zero understanding of the complexity issue.
and yet client code can be incredibly simpler nowadays thanks to all these features. 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…