Hacker News new | ask | show | jobs
by kodra 1039 days ago
Why can't it add keywords? Adding a new keyword doesn't break backward compatibility. It breaks "forward compatibility."
2 comments

New keywords are like the textbook example of a backwards compatibility problem. It's probably why C overloads "static" so many different ways.
You can sort of add new keywords backwards-compatibly using a trick called "contextual keywords": you require that they be placed in a syntactic position in which no identifier could legally go, and you maintain them as legal identifiers for compatibility. C++ used this trick to introduce "final" and "override" by moving them before the opening "{".
You mean new reserved words? For example, I'm quite sure when C# added "record" it didn't break backward compatibility, as old code that uses "record" as a variable name still compiles.
Go has made changes like that by adding new predeclared identifiers ("any" is an example, I think?) but there's a distinction between predeclared identifiers and keywords.
Old code becoming a compiler error sound like a backwards compatibility issue to me.
I guess it's a terminology thing. As someone from a C# background, not all keywords are reserved words. Only new reserved words break backward compatibility.

C# has added some keywords (record, and, or) without breaking backwards compatibility.