2 ms·
Every keyword (unlike a symbol in std::) risks colliding with existing code, so reuse is greatly preferred. Yes, it is, to be diplomatic, highly imperfect, but
by gumby 3y ago
Every keyword (unlike a symbol in std::) risks colliding with existing code, so reuse is greatly preferred.
Yes, it is, to be diplomatic, highly imperfect, but working to avoid breaking existing code is one reason C++ is so successful.
- zabzonk 3y agoyeah, i know all about that. but still, i think that c++ (and c, for that matter) could do with more alphabetic keywords. and after all, the original language introduced quite a few!
- badsectoracula 3y agoWouldn't C's approach with macros help? E.g. the language defines a keyword like _Foobar which is supposed to be used via #include <foobar> that defines a "#define foobar _Foobar" macro, thus avoiding any collisions with existing code and any new code that needs to use the new keyword can opt-in and deal with any collisions (since the code will be modified anyway).
- zabzonk 3y agostroustrup's ambition for c++ was to get rid of the preprocessor (unfufilled, sadly). also, defining a name such as _Foobar does not avoid a clash with existing code - names like that are reserved in c++ and may be used by the standard library.
- dkersten 3y agoThe standard library is at least under the control of the people implementing the standard, which is much smaller breakage (ie can be fixed at the time of implementing support for the keyword) than breaking a random users code. The standard could go as far as to say what <foobar> should provide and then leave it up to the implementation what the actual non-aliased keyword actually is: maybe it’s _Foobar or maybe it’s something else, the end user won’t know because you just use foobar after including <foobar>
- gumby 3y agoI would not like this at all. Keyword are part of the compiler; libraries (header files, modules, what have you) are not. It’s perfectly legit to write and use a program that doesn’t use anything in std:: I know this is a bit of an “angels on the head of a pin” position to take.