Wow, I recently started a position developing safety-critical software and that really clears up why we use brace-initialization. It seems to just work for most things. Thanks for that!
Never once I've seen the trust towards the committee fall as low as it did when people in my company started to migrate to C++11 and realized that this is their life now. Haven't recovered since, to be honest.
The example is de-obfuscated, obviously: it's usually an issue somewhere deep, sometimes in templated code where you don't even know what the types are just by looking at the code. In a large enough company with enough people coming and leaving and a moderately relaxed review process, you are pretty much guaranteed to have a steady flow of bugs like this. It's a footgun with infinite ammo.
I sort of understand why this happened, but it feels like we as a community completely failed to do things right for once, so that we could stop teaching all other initialization methods to people and pretend that the () syntax doesn't exist and shouldn't be used anymore.
Now I see mixed-style initialization lists all the time (see the bonus part from the link above), and cry internally from time to time while thinking about this whole situation.
It could be a std::vector<size_t>, in which case all types would strictly match.
The core issue here is the special behavior of std::initializer_list (see the notes here), which I guess can be called an "implicit conversion" in a very broad sense, so your point stands.
I was really hoping that they will deprecate this nonsense immediately, and possibly introduce a non-ambiguous way to construct initializer lists in C++14, but by now we probably have too much code relying on this brittle behavior to change anything.
Now the only safe solution would be to abandon the braces and introduce yet another strictly distinct and unambiguous syntax for initialization, but at that point I'm afraid half of the developers would simply give up and switch to Rust.
Existing code is always the problem, and C++ is terrible at removing features.
Say, you have millions of lines that expected that something like std::vector<int> v{64}; constructs a vector with one element 64.
Now with your proposal you are silently changing the behavior of millions of lines of code in tens of thousands of projects. The code still compiles, and even runs, but the behavior is different.
Some of the behavioral changes may go undetected by tests.
Some of them would have devastating consequences, costing billions of dollars, or even human lives.
It's a recurring theme in C++: everything sort of sucks because by the time we understood why it sucks, the feature became so heavily-used that you can't simply remove it. It took decades to get rid of std::auto_ptr, and we only succeeded because it was already banned by the majority of teams for being hopelessly broken. And it wasn't a silent change: the code properly stopped compiling in C++17, which allowed the developers to go and fix stuff if they didn't have time for that during the 6 years of deprecation.
That's why epochs are a huge deal if they'll ever be accepted in some form or another. We will finally, finally be able to start fixing and removing stuff instead of simply piling up more and more stuff until no one understands what's going on in this language.
The standard committee should really have fixed this before C++11. The epochs proposal seems interesting. Though I prefer throwing away backward compatibility in some future version of C++, and fix all the problems mentioned in that proposal (and many other problems not covered in that proposal). To avoid confuse users, that new version of C++ should be given a new name,like "Simplified C++ ". Some tools should be able to automatically refactor C++ code to "Simplified C++" code, maybe with some help from programmers. Those who want to stick to C++ could still use C++, and those who want to use simplified C++ could move on with it. The epochs proposal, if accepted, I am afraid will open the floodgate of numerous dialects/flavors of C++ code coexisting and tangling together. Google will have its Google epoch, and Facebook will have Facebook epoch, and there will at least be a C++-core-guideline epoch. That won't be beautiful. Beside numerous rules of C++, programmers now need to know specific rules that are allowed in each epoch.
103
u/atimholt Mar 01 '21
I prefer it as a table.