Skip to content

Commit 785929b

Browse files
committed
Added "Evolving code without breaking binary compatibility" section + minor updates/rewording
1 parent c0a0501 commit 785929b

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

_overviews/tutorials/binary-compatibility-for-library-authors.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ if we say that any library release of `v1.x.x` will be forwards compatible, we c
5252

5353
(For the rest of this guide, when you see the word "compatible" assume backwards compatibility, as it is the more common case of compatibility guarantee)
5454

55-
An important note to make is that while breaking source compatibility normally results in breaking binary compatibility, they are actually orthogonal
56-
(breaking one does not imply breaking the other). See below for more examples (TODO: make sure we have examples?)
57-
TODO: more facts?
55+
An important note to make is that while source compatibility breakages normally results in binary compatibility breakages as well, they are actually orthogonal
56+
(breaking one does not imply breaking the other).
5857

5958
## Why binary compatibility matters
6059

@@ -88,19 +87,39 @@ How can we, as library authors, spare our users of runtime errors and dependency
8887
* **Avoid breaking binary compatibility** through careful design and evolution of your library interfaces
8988
* Communicate binary compatibility breakages clearly through **versioning**
9089

91-
## MiMa - Check Binary Compatibility with Previous Library Versions
90+
## MiMa - Check binary compatibility with previous library versions
9291

93-
The [Migration Manager for Scala](https://github.com/typesafehub/migration-manager) (MiMa) is a tool for diagnosing binary incompatibilities between different library versions.
92+
The [Migration Manager for Scala](https://github.com/typesafehub/migration-manager) (MiMa) is a tool for diagnosing binary incompatibilities between different library versions.
93+
It works by comparing the class files of two provided JARs and report any binary incompatibilities found.
9494

95-
When run standalone in the command line, it will compare the .class files in the two provided JARs and report any binary incompatibilities found. Most library authors use the [SBT plugin](https://github.com/typesafehub/migration-manager/wiki/Sbt-plugin)
96-
to help spot binary incompatibility between library releases. (Follow the link for instructions on how to use it in your project)
95+
By incorporating [MiMa SBT plugin](https://github.com/typesafehub/migration-manager/wiki/Sbt-plugin) into your SBT build, you can easily check whether
96+
you have accidentally introduced binary incompatible changes. Detailed instruction on how to use the SBT plugin can be found in the link.
9797

98-
## Designing for Evolution - without breaking binary compatibility
98+
We strongly encourage every library author to incorporate MiMa into their library release workflow.
9999

100-
TODO
100+
## Evolving code without breaking binary compatibility
101+
102+
Binary compatibility breakages can often be avoided through careful use of certain Scala features as well as some techniques you can apply when modifying code.
103+
104+
Some language features may break binary compatibility:
105+
106+
* Default parameter values for methods or classes
107+
* Case classes
108+
* Default methods on traits (doesn't cause breakages since 2.12)
109+
110+
Techniques you can use to avoid breaking binary compatibility:
111+
112+
* Annotate public methods's return type explicitly
113+
* Mark methods as package private when you want to remove a method or modify its signature
114+
* Don't use inlining (for libraries)
115+
116+
For brevity of this guide, detailed explanation and runnable code examples can be found in [Binary Compatibility Code Examples & Explanation](https://github.com/jatcwang/binary-compatibility-guide).
117+
118+
Again, we recommend using MiMa to double check that you have not broken binary compatibility after making changes.
101119

102120
## Versioning Scheme - Communicate binary compatibility breakages
103121

122+
### Recommmended Versioning Scheme
104123
We recommend using the following schemes to communicate binary and source compatibility to your users:
105124

106125
* Any release with the same major version are **Binary Backwards Compatible** with each other

0 commit comments

Comments
 (0)