3 ms·
My biggest problem with SemVer is that determining what is and isn't a breaking change can be very hard in modern languages. Worse yet, if the library is invoke
by int_19h 8y ago
My biggest problem with SemVer is that determining what is and isn't a breaking change can be very hard in modern languages. Worse yet, if the library is invoked from a different language, some things that weren't breaking can become so (and vice versa). And sometimes, said different language is actually a new version of the same language.
For example, in C#, is adding a new overload to a sealed class a breaking change? The general consensus is "no", but doing that can easily break existing code by making it ambiguous (if there was only one implicit conversion or upcast to consider before, but now there are two).
But what about adding a new method, with a completely different name - surely that's not breaking (to remind, our class is sealed, so there's no descendants; and in C#, methods don't override base class unless explicitly requested)? It wasn't - until C# 3.5 added extension methods. Now, every time you add a new method to your class, you are potentially breaking someone else's extension method with the same signature - and worse yet, it will compile silently, and just call a different thing.
Okay, what about adding a new property? Can't be overloaded, and there's no extension properties (yet; they might still be added). There's still a problem: when calling an overloaded method with a lambda - also added in C# 3.5 - as an argument, one of the criteria for choosing an overload is that the body of the lambda is valid after substituting the types for that particular overload - this includes checking members. For example, suppose we have:
class Foo {}
class Bar {
public void Frob() {}
}
class Program {
static void Qux(Action<Foo> a) {}
static void Qux(Action<Bar> a) {}
static void Main() {
Qux(x => x.Frob());
}
}
This compiles, because only Bar has Frob, and thus Qux(Action<Bar>) is the correct overload. But if Foo also gets some Frob at some future point, this code breaks - the overload is ambiguous now. In more complicated cases with other types involved, this can also result in a silent choice of a different overload.
But, on the other hand, if you were to use the same class from F#, it wouldn't be a problem, because it simply doesn't try to do this sort of type inference on top of overloading. So for F#, this isn't breaking at all... today. It might be tomorrow, though, as it was with the extension method example above (F# didn't add support for those for a while after C# did, so it wasn't broken by that initially).
I guess the TL;DR is that "breaking API change" is an oversimplification of the real thing - in reality, what's breaking depends on the entire toolchain and the way the library is used by the client code, not just the API itself. So our criteria for a major semver increase simply aren't well-defined. And that needs to be done - separately for various languages due to different semantics - before any given version number can be more than just one person's guess.
- steveklabnik 8y agoSemVer itself as a spec expects projects to define exactly what compatibility means, it's true. We went through all of these kinds of cases with Rust, for example, and defined what kinds of changes increase what kinds of version numbers. Given that it's based on language features, it gives a good basis for the ecosystem, but when you don't have that basis, yeah it's much much tougher.
- int_19h 8y agoIs there any kind of centralized place where "what does semver breaking change means for language X" can be aggregated? I think it can be useful, at least until this is something that language designers routinely include in specs. But there's remains the question of what happens if a library is written in one language, but used from many others with different features that can make non-breaking changes breaking, and vice versa. One could say that the owner of the library is generally not responsible for breaking other languages, but in many cases the library is cross-language by design.
- steveklabnik 8y agoNot currently. Rust has done this, but I'm not aware of other languages having done so.