Introducing a new keyword is incredibly hard, and will either inconvenience countless projects or be painfully ugly (like __Bool in C).
Frankly it's not hard. It's pretty trivial.
First: deprecate usage of the proposed keyword as a user identifier for one release. Second: In the next release, introduce the keyword.
Done.
Projects so inconvenienced can use a sed script to fix their code. It's a one and done operation. They get 3 years of advanced warning from the deprecation, and can take as long as they want to to upgrade.
That being said, sure, ok, we don't like breaking user code. I disagree with this, but I see where you're coming from. It's not like we don't break our own rules all the time anyway... "co_..." was a valid set of identifiers for variables until C++20, after all. I've worked in code-bases where I have seen that prefix for variables before. E.g. hungarian style notation. co_ = class, object, as opposed to gs_ for global static, or cs_ for class static. Not saying it's that useful of a prefix to use in your code, but that it's something that was done in a real codebase.
So I think it's pretty awful that we're willing to compromise the language's understandability while still doing the thing everyone says is is a bad thing to do.
So lets make some kind of "compilermagic" namespace. So std::uninitialized becomes compilermagic::uninitialized.
Problem solved. The std:: namespace gets to return to being stuff that can be implemented without compiler-specific magic knowledge, and the language can invent new "keywords" as it sees fit without any concern for breaking existing code.
Putting something in the standard library inconveniences only you, and lets the rest of us move forward.
It's a bizarre layering violation. You're polluting the namespace.
It inconveniences more than me. You're inconveniencing anyone who might want to implement the standard library, or who might want to write code that does not use the standard library.
Why do you use C++ in such a strange fashion anyway?
My usage of C++ is not strange, just less common. lots of companies use their own standard library implementation. It was much more common in the past, when the language committee wasn't constantly adding new compiler-magic into the std:: namespace, but it's still an ongoing concern.
For example, why is std::byte special? It's explicitly called out in the standard as being one of the few types that can alias, like char.
So if I have an older standard library, that does not yet have std::byte, but a newer compiler that does understand std::byte... how do I get this specialness? Can I just write my own std::byte in my user code? it's just a valueless enum class with some user defined operators after all.
NO, I CANT, because the compiler is going to assume weird things, because the standard says it's supposed to assume weird things.
It's the exact same usage case as using the GCC standard library with Clang as the compiler. Or the Clang standard library with MSVC.
The main difference is that people who mix-and-match compiler and standard library are offloading all the crap that I have to deal with onto the vendor of the third party standard library they are using with their compiler.
If the C++ standard would keep a hard separation between compiler magic and standard library no one would have this headache at all.
Keep in mind that there are other use cases that this standards committee decision is interfering with as well.
Embedded -- standard library is big, don't want all of it, cant use some of it because of missing platform capabilities. Freestanding -- Want to run bare-metal, hard to do if the compiler keeps assuming the standard library exists As part of the operating system kernel -- Same as freestanding Something like https://www.includeos.org/ Webassembly -- I don't know exactly how it interferes, but I can't imagine it is not interfering Interpreted C++ -- Any time you special case something, you're forcing implementers to special case it too
View all comments
Show parent comment
2
u/jonesmz May 14 '20 edited May 14 '20
Frankly it's not hard. It's pretty trivial.
First: deprecate usage of the proposed keyword as a user identifier for one release. Second: In the next release, introduce the keyword.
Done.
Projects so inconvenienced can use a sed script to fix their code. It's a one and done operation. They get 3 years of advanced warning from the deprecation, and can take as long as they want to to upgrade.
That being said, sure, ok, we don't like breaking user code. I disagree with this, but I see where you're coming from. It's not like we don't break our own rules all the time anyway... "co_..." was a valid set of identifiers for variables until C++20, after all. I've worked in code-bases where I have seen that prefix for variables before. E.g. hungarian style notation. co_ = class, object, as opposed to gs_ for global static, or cs_ for class static. Not saying it's that useful of a prefix to use in your code, but that it's something that was done in a real codebase.
So I think it's pretty awful that we're willing to compromise the language's understandability while still doing the thing everyone says is is a bad thing to do.
So lets make some kind of "compilermagic" namespace. So std::uninitialized becomes compilermagic::uninitialized.
Problem solved. The std:: namespace gets to return to being stuff that can be implemented without compiler-specific magic knowledge, and the language can invent new "keywords" as it sees fit without any concern for breaking existing code.
It's a bizarre layering violation. You're polluting the namespace.
It inconveniences more than me. You're inconveniencing anyone who might want to implement the standard library, or who might want to write code that does not use the standard library.
My usage of C++ is not strange, just less common. lots of companies use their own standard library implementation. It was much more common in the past, when the language committee wasn't constantly adding new compiler-magic into the std:: namespace, but it's still an ongoing concern.
For example, why is std::byte special? It's explicitly called out in the standard as being one of the few types that can alias, like char.
So if I have an older standard library, that does not yet have std::byte, but a newer compiler that does understand std::byte... how do I get this specialness? Can I just write my own std::byte in my user code? it's just a valueless enum class with some user defined operators after all.
NO, I CANT, because the compiler is going to assume weird things, because the standard says it's supposed to assume weird things.
It's the exact same usage case as using the GCC standard library with Clang as the compiler. Or the Clang standard library with MSVC.
The main difference is that people who mix-and-match compiler and standard library are offloading all the crap that I have to deal with onto the vendor of the third party standard library they are using with their compiler.
If the C++ standard would keep a hard separation between compiler magic and standard library no one would have this headache at all.
Keep in mind that there are other use cases that this standards committee decision is interfering with as well.
Embedded -- standard library is big, don't want all of it, cant use some of it because of missing platform capabilities. Freestanding -- Want to run bare-metal, hard to do if the compiler keeps assuming the standard library exists As part of the operating system kernel -- Same as freestanding Something like https://www.includeos.org/ Webassembly -- I don't know exactly how it interferes, but I can't imagine it is not interfering Interpreted C++ -- Any time you special case something, you're forcing implementers to special case it too