4 ms·
Variables like "valueSet" scream out that the language lacks a Maybe type instead. One of the worst things about C++ is that it's content to basically not bothe
by tialaramex 2y ago
Variables like "valueSet" scream out that the language lacks a Maybe type instead. One of the worst things about C++ is that it's content to basically not bother improving on the C type system.
- rowanG077 2y agoC++ has a maybe type. It's called std::optional.
- uecker 2y agoHere is my experimental maybe type for C: https://godbolt.org/z/YxnsY7Ted https://godbolt.org/z/YxnsY7Ted
- tialaramex 2y agoSix divided by minus one is a "Division by zero" now? Where I come from that's minus six. Good luck to WG14 (or maybe a faction within it?) as they seem to have decided to go make their own C++ competitor now, it's a weird time to do that, but everybody needs a hobby.
- uecker 2y agoYeah, I was about to add the test for INT_MIN / -1 but got distracted, but also not really the point of the example anyway. I hope you realize that this is example does not need any complex C++ features.
- tialaramex 2y agoI mean, sure. I read the "noplate" code. Did you ever watch the Mrs Merton show? "So, what first attracted you to the millionaire Paul Daniels?". There's a reason you felt the need to insist that your C language generic containers aren't relying on "complex C++ features" whatever you might decide that means.
- uecker 2y agoThe issue with C++ is that it is a hyper-complex language that really is a combination of four languages: C with classes, template code, macros, and constexpr code with largely overlapping functionality. It seems to be getting better in amalgamating these different parts, but it is still a mess that annoys me all the time when I try to use it. This complexity is what drove me away. Still there is a unmet need for generic programming in C and I can now do this with macros very well means I can have it without missing this part from C++. So the idea is not to reinvent C++ but to make minor tweaks to C to be able to do similar things in a much simpler way.
- maccard 2y agoC++ has optional, but I wanted to demonstrate that you could wrap a C API in a safer more ergonomic way. If you rewrote it in a more modern way and changed the API std::optional<int> getFoo(); if (auto val = getFoo()) {} There are lots of improvements over C’s type system - std.array, span, view, hell even a _string_ class
- pjmlp 2y agoI would vouch that C++ has plenty of improvements of C type system, even C++ARM already provided enough improvements that I never liked plain old C, other than that year spent learning C via Turbo C 2.0, before being given access to Turbo C++ 1.0 for MS-DOS in 1993. The problem is all the folks that insist coding in C++ as if it was C, ignored all those C++ improvements over C.