News for hackers. Stuff that matters.
Re:Backward Compatibility, Go 1.21, and Go 2 by dcow on Monday August 14, 2023 @01:03PM (#37123487)
You might be overestimating the type of change required to break source compatibility. A benign example is adding a keyword. Let's say you want to add a new language feature and the community unarguably wants the feature and the right or only way to add it is with a new keyword. If you're not allowed to break source, then you can never add the feature.

I understand your argument for big things like changing the semantics of the language. But a backwards-incompatible change can also be rather benign.

Re:Backward Compatibility, Go 1.21, and Go 2 by rsc on Monday August 14, 2023 @01:13PM (#37123643)
It's not true that Go can't add new keywords. Now that we have Go modules, all Go code is now explicitly annotated with the version of Go it was written against. We can add a new keyword in a later version of Go as long as the compiler can still also compile code written for the older versions of Go. (The go command tells the compiler which version of Go to use for each package it compiles.)

What we're not going to do is abandon all the code written for older versions of Go, like Python 3 or Perl 6 did. Python is recovering now but it easily lost a decade to the Python 2 -> Python 3 transition, almost certainly unnecessarily. And Perl lost even more.

Re:Backward Compatibility, Go 1.21, and Go 2 by jen20 on Monday August 14, 2023 @09:52PM (#37129210)
This is a the TL;DR I wish was the first paragraph of the article!

Could this mechanism be used to patch up unfortunate evolutions in the standard library also? For example, all of the `WithContext` functions that could be folded into the (more common?) non-contextful versions?

Re:Backward Compatibility, Go 1.21, and Go 2 by kodra on Monday August 14, 2023 @01:16PM (#37123671)
Why can't it add keywords? Adding a new keyword doesn't break backward compatibility. It breaks "forward compatibility."
Re:Backward Compatibility, Go 1.21, and Go 2 by tptacek on Monday August 14, 2023 @01:37PM (#37123973)
New keywords are like the textbook example of a backwards compatibility problem. It's probably why C overloads "static" so many different ways.
Re:Backward Compatibility, Go 1.21, and Go 2 by kodra on Monday August 14, 2023 @01:40PM (#37124017)
You mean new reserved words? For example, I'm quite sure when C# added "record" it doesn't break backward compatibility, as old code that uses "record" as a variable name still compiles.
Re:Backward Compatibility, Go 1.21, and Go 2 by tptacek on Monday August 14, 2023 @01:59PM (#37124281)
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.
Re:Backward Compatibility, Go 1.21, and Go 2 by pcwalton on Monday August 14, 2023 @04:06PM (#37126137)
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 "{".
Re:Backward Compatibility, Go 1.21, and Go 2 by Dylan16807 on Monday August 14, 2023 @01:22PM (#37123745)
Old code becoming a compiler error sound like a backwards compatibility issue to me.
Re:Backward Compatibility, Go 1.21, and Go 2 by kodra on Monday August 14, 2023 @01:45PM (#37124084)
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.

Re:Backward Compatibility, Go 1.21, and Go 2 by crickey on Monday August 14, 2023 @01:15PM (#37123659)
I dont undestand your example, plenty of languages add new keywords without breaking backwards compatibility, its removing a keyword that would cause such and issue.
Re:Backward Compatibility, Go 1.21, and Go 2 by meepmorp on Monday August 14, 2023 @01:38PM (#37123988)
I have named a function 'foo', in current version of language. A future change makes 'foo' a keyword. My code was broken by adding a keyword.
Re:Backward Compatibility, Go 1.21, and Go 2 by earthboundkid on Monday August 14, 2023 @01:55PM (#37124236)
This is not theoretical: Python broke a lot of async packages when they made “async” a keyword!
Re:Backward Compatibility, Go 1.21, and Go 2 by crickey on Monday August 14, 2023 @06:22PM (#37127522)
I guess, some languages get around this by having a destinction between functions and keyword functions not having the () braces in the syntax. But really if ur defning functions as keywords u should just put it in the standard library