News for hackers. Stuff that matters.
Re:Backward Compatibility, Go 1.21, and Go 2 by the_duke on Monday August 14, 2023 @12:52PM (#37123304)
Never breaking compatibility is hardly a new idea.

Java and C++ have invested tremendous amounts of effort into preserving backwards compatibility for decades, often requiring bending over backwards and very suboptimal designs for new features, especially in C++.

But it keeps users happy. At least the ones with large old code bases.

I think Rust has one of the best models: editions.

The compiler will always support old code written against older editions, but the language can still introduce breaking changes in newer editions. Developers can either opt in to new editions and migrate their code, or do nothing, and things continue to work fine. There is seamless/transparent interoperability.

Of course Rust is still pretty young, and if this model will work long term remains to be seen. For example, I imagine this causes a lot of implementation complexity in the compiler, the standard library is much more restricted and must remain stable across editions, and major overhauls probably won't be possible.

But so far it has worked out really well, allowing the team to fix warts and mistakes in the language.

Re:Backward Compatibility, Go 1.21, and Go 2 by glenjamin on Monday August 14, 2023 @01:16PM (#37123670)
Did you read the article?

> The compiler will always support old code written against older editions, but the language can still introduce breaking changes in newer editions. Developers can either opt in to new editions and migrate their code, or do nothing, and things continue to work fine. There is seamless/transparent interoperability.

This is exactly what the GODEBUG scheme described in the article is intended to allow.

Re:Backward Compatibility, Go 1.21, and Go 2 by the_duke on Monday August 14, 2023 @01:28PM (#37123827)
Yes I did, but the proposed solution is somewhat inferior to the Rust approach to me.

> We will define a new GODEBUG setting that allows individual programs to opt out of the new behavior.

The setting is opt-out, requiring manual intervention.

> GODEBUG settings added for compatibility will be maintained for a minimum of two years (four Go releases)

So there is no indefinite backwards compatibility, like with Rust.

> A program can change individual GODEBUG settings

So you need to potentially very carefully monitor your settings, and be mindful of how you deal with them. This can also theoretically lead to a pretty big complexity explosion. The mess that is Haskell langauge features comes to mind, which can be enabled or disabled per source file, and are sometimes incompatible...

This also means that you can't have differing settings for different libraries, it's application-wide configuration.

I'm sure this will be mitigated in Go by using these feature toggles very conservatively, by still avoiding those changes where possible, and by tooling that helps to migrate.

But the Rust approach still seems preferable to me. As mentioned, though, the Rust approach currently doesn't account for standard library changes, which would sometimes be possible, but hard to pull off.

Re:Backward Compatibility, Go 1.21, and Go 2 by vocx2tx on Monday August 14, 2023 @01:55PM (#37124224)
> The setting is opt-out, requiring manual intervention.

No. If a module's go.mod files declares go1.21, the compiler will use go1.21 semantics when building it, even if 1.22 has already been published and the module is being used from a 1.22-enabled program. This is explicitly mentioned in the blog post.

Re:Backward Compatibility, Go 1.21, and Go 2 by tick_tock_tick on Monday August 14, 2023 @03:27PM (#37125660)
It's basically a much more featured, flexible, extendable, and usable version of editions. Anything you could do with editions you could do with this; you could implemented "editions" via this functionality.
Re:Backward Compatibility, Go 1.21, and Go 2 by the_duke on Monday August 14, 2023 @04:26PM (#37126362)
Yes, but that's sort of my point regarding complexity.

"This crate is edition X, and an edition comes out every 3 years or so" is much easier to deal with.

It reminds me a bit of Haskell language pragrams, which can be toggled per source file (module), and which are a huge mess.

Re:Backward Compatibility, Go 1.21, and Go 2 by izacus on Monday August 14, 2023 @01:30PM (#37123870)
Can you explain in what way is that different from e.g. C++, where a compiler will take "-std=<C++ revision>" parameter which chooses the "edition" of the language?

And even link different versions together?

Because it sounds like Rust uses the same approach with the benefit of not hitting all the problems this causes... yet.

Re:Backward Compatibility, Go 1.21, and Go 2 by kaba0 on Monday August 14, 2023 @03:26PM (#37125641)
I would also be interested in it. As far as I know editions only allow for syntax changes, the semantics will change if incompatible, especially that Rust doesn't link across different versions in the same way as C++ does.
Re:Backward Compatibility, Go 1.21, and Go 2 by uluyol on Tuesday August 15, 2023 @12:59AM (#37130368)
C++ unfortunately does textual inclusion for header files. So "-std=" does not automatically work for those. You need to sprinkle in #ifdefs rather than getting automatic forward compatibility.
Re:Backward Compatibility, Go 1.21, and Go 2 by zigzag312 on Monday August 14, 2023 @01:12PM (#37123628)
I would upvote this twice if I could.

We will never break compatibility is code for "we will never fix warts and mistakes in the language".

Re:Backward Compatibility, Go 1.21, and Go 2 by tptacek on Monday August 14, 2023 @01:56PM (#37124248)
It obviously isn't, as the text of the article repeatedly observes.
Re:Backward Compatibility, Go 1.21, and Go 2 by zigzag312 on Tuesday August 15, 2023 @04:12AM (#37131444)
You are right. I haven't read the article and just assumed. It's actually about how they enabled introducing "breaking" changes without actually breaking backwards compatibility with existing code. Which is best possible outcome.