# A Guide on Binary Compatibility - need your input!

**URL:** <https://contributors.scala-lang.org/t/a-guide-on-binary-compatibility-need-your-input/1089>\
**Category:** Documentation\
**Created:** [September 7, 2017, 12:27pm UTC](https://contributors.scala-lang.org/t/a-guide-on-binary-compatibility-need-your-input/1089 "2017-09-07T12:27:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sjrd](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sjrd/32/24_2.png) [@sjrd](https://contributors.scala-lang.org/u/sjrd)\
**Post date:** [September 7, 2017, 1:28pm UTC](https://contributors.scala-lang.org/t/a-guide-on-binary-compatibility-need-your-input/1089/2 "2017-09-07T13:28:54Z")

</div>

> [@jatcwang](#):
>
> Versioning scheme (e.g. minor version bump normally means binary incompatibility with the last point release)

This is not the right thing to do, because it is useless. A much more useful version scheme is the following:

- Bump _minor_ version if the new release contains (likely) _source_ incompatibilities
- Bump _major_ version if the new release contains _binary_ incompatibilities

This versioning scheme assumes that binary incompatibilities are _worse_ than source incompatibilities. Why is that? Because of the dependency diamond problem. Let me explain.

If you are the author of an application `App`, you don’t care about writing it with binary or source compatibility in mind, because no one depends on you.

If you are the author of a library `A` used by some applications `App`s, binary compatibility is still irrelevant to you. If you publish a new version, then either an `App` upgrades and it will recompile with your new version, or it doesn’t upgrade. In no scenario will it compile with version _x_ but link with version _y_. Of course, you want to care about source compatibility so that the `App`s can easily upgrade to your new version, but it’s not a _big_ deal if you break source compat. At the time of the upgrade, the `App` can adapt to your source incompatible changes. They can also not upgrade if they don’t want to.

Compatibility becomes critical if you are the author of a library `X`, used by several _libraries_ `A`, `B`, etc., themselves used by applications `App`s (or further libraries down the line). To make things concrete, consider the following scenario:

- `A` version _a1_ depends on `X` version _x1_
- `B` version _b1_ depends on `X` version _x1_
- `App` depends on `A` v _a1_ and `B` v _b1_.

Now let’s say you publish a new version `x2` of `X`. If this version is source incompatible with `x1`, but binary compatible, the following happens. `A` can upgrade to `X` version _x2_ and publish version _a2_. At this point, it might need to change its source code to account for the source incompat of `X`, but that’s fine. The important thing is that `App` can upgrade to `A` version _a2_. Now we have a funny thing: `App` depends on `A` _a2_ which depends on `X` _x2_, and `App` depends on `B` _b1_ which depends on `X` _x1_. Note that when upgrading `App` had to take into account source incompats of `A`, and _possibly_ source incompats of `X` _x2_, assuming the source code of `App` directly references things from `X`. But the important thing is that it now has two versions of `X` on its linking classpath; of course _x1_ is evicted. That means that we link `App`, `A` _a2_, `B` _b1_ and `X` _x2_ together. Oh look! there’s `B` _b1_ which expected `X` _x1_ but it receives _x2_. That is _not_ an issue, however, because `X` evolved in a binary compatible way (even if not source compatible).

What you need to see here, is that despite source incompatibilites, the path through `A` could perform upgrades, and `App` could depend on new versions of `A` and `X`, without `B` having to do _anything_.

Now what if the changes were binary _incompatible_. In that situation, we are stuck. `App` _cannot_ upgrade `A` _because of `B`_! `App` is stuck with `A` _a1_ until a new release of `B` comes up that depends on `X` _x2_. What if, in the meantime, `X` published _x3_, and `B`’s maintainer decides to go straight to `X` _x3_?

In case of binary incompatibilities in the upper parts of the dependency graph can prevent from upgrading a branch of the graph without also upgrading _unrelated_ other branches of the graph. This is _dependency hell_. Add a couple more libraries to the mix besides `A` and `B`, and `App` can never ever upgrade any of its libraries in a way that they all work together.

Source incompatibility does not have this unrelated branches issue. You can _always_ upgrade any part of the graph, including `App`, to newer versions of parts of its dependency graph, without being impacted by other parts of your dependency graph.

**This is a very, very important point.** Binary compatibility is _more important_ than source compatibility! That is because binary incompatibilities lead to dependency hell, while source incompatibilities do not.

Therefore, breaking binary compatibility should be something _extreme_ that requires a major version bump. Breaking source compatibility is not that big a deal, and only deserves a minor version bump. From a technical point of view, this is the only versioning scheme that makes sense for Scala libraries.

---

_[View the full topic](https://contributors.scala-lang.org/t/a-guide-on-binary-compatibility-need-your-input/1089)._
