The SemVer Talk 1.0

A presentation at Web Directions Code Melbourne in August 2016 in Melbourne VIC, Australia by Ben Buchanan (200ok)

Slide 1

Slide 1

The SemVer Talk 1.1.0 Web Directions Code 2016 Ben Buchanan, @200okpublic command-line.net

Slide 2

Slide 2

Versions everywhere { “dependencies”: { “express”: “~4.13.3”, “grunt­cli”: “~0.1.13”, “mustache”: “~2.2.1”, “socket.io”: “~1.3.7” } }

Slide 3

Slide 3

1.nervous.0.0.kumquat.1469273302.7

Slide 4

Slide 4

Version schemes Sequential Date of release Degree of change Degree of compatibility Random ^%#@

Slide 5

Slide 5

ReadMyBlogVer Where the versions mean nothing, you just have to read their blog.

Slide 6

Slide 6

ReadMyBlogVer doesn’t scale reveal.js uses 484 NPM packages. 484 * 2 minutes = ~16 hours.

Slide 7

Slide 7

People don’t read your blog Your API is a tiny piece of a much larger experience.

Slide 8

Slide 8

Enter Semantic Versioning… SemVer communicates changes to a public API.

Slide 9

Slide 9

semver.org SemVer is the most popular version scheme in web development.

Slide 10

Slide 10

Most popular? Preferred in most current dev stacks. 91% of Hashnoders surveyed* use it. * survey was not in any way scientific.

Slide 11

Slide 11

Semantic adjective Relating to meaning in language or logic.

Slide 12

Slide 12

SemVer is… A degree of compatibility scheme. SemVer describes changes to the API.

Slide 13

Slide 13

Anchored to 1.0.0 0.x.y = early development 1.0.0 = first public API 2.0.0 = first breaking change

Slide 14

Slide 14

SemVer is not… Based on the size, number, or general vibe of the changes.

Slide 15

Slide 15

SemVer is not… Guessing if your code works, or estimating your upgrade work.

Slide 16

Slide 16

1.2.3 1 = major 2 = minor 3 = patch

Slide 17

Slide 17

1.2.3 1 = major 2 = minor 3 = patch

Slide 18

Slide 18

1.2.3 1 = major 2 = minor 3 = patch

Slide 19

Slide 19

1.2.3 1 = major 2 = minor 3 = patch

Slide 20

Slide 20

Pre-release & Build 1.2.3-beta.1 1.2.3-beta.1+001

Slide 21

Slide 21

Precedence 1.2.3 ↑ 1.2.3-beta.1 1.2.3-beta.1+001 (builds ignored)

Slide 22

Slide 22

X.Y.Z Three numbers, not one. Each increments sequentially. Each increments indefinitely.

Slide 23

Slide 23

1.9.0 Can but does not have to increment to 2.0.0

Slide 24

Slide 24

1.9.0 can increment to 2.0.0 1.10.0 1.9.1

Slide 25

Slide 25

What do the terms mean? Major = breaking changes Minor = new features Patch = bug fixes

Slide 26

Slide 26

Breaking changes Code changes which are not backwards-compatible are called breaking changes.

Slide 27

Slide 27

Imagine this API: // returns a small black coffee COFFEE.gimme(‘large’) Wait, large returns small ?

Slide 28

Slide 28

Next release // returns a large black coffee COFFEE.gimme(‘large’) Fixed! That’s a patch: 1.0.1

Slide 29

Slide 29

Next release // adds types of coffee COFFEE.gimme(‘large’, ‘latte’) New feature! That’s a minor: 1.1.0

Slide 30

Slide 30

Next release // has a more extensible format COFFEE.gimme({ ‘size’:’large’, ‘type’:’latte’ }) // but old calls no longer work COFFEE.gimme(‘large’, ‘latte’) That’s a breaking change: 2.0.0

Slide 31

Slide 31

Shorthand SemVer compresses information.

Slide 32

Slide 32

We judge risk every day Update available 1.7.7 → 1.7.9 Run npm i ­g bower to update

Slide 33

Slide 33

How risky is this upgrade? 1.0.0 to 2.0.0 = dangerous 1.0.0 to 1.1.0 = safe 1.0.0 to 1.0.1 = safe

Slide 34

Slide 34

What will happen when I upgrade? 1.0.0 to 2.0.0 = things will break 1.0.0 to 1.1.0 = you can use something new 1.0.0 to 1.0.1 = something was fixed

Slide 35

Slide 35

What do I need to read? 1.0.0 to 2.0.0 = upgrade guide, definitely 1.0.0 to 1.1.0 = release notes, maybe 1.0.0 to 1.0.1 = nothing

Slide 36

Slide 36

Non-code SemVer Versions can help with design, copy…

Slide 37

Slide 37

Does this look familiar? website-new.psd website-new_new.psd website-new_new-blue.psd website-new_new-with-bigger-logo.psd website-new-final.psd website-new-final-fixed.psd

Slide 38

Slide 38

Better! website-0.1.psd website-0.2.psd website-1.0.psd website-1.0.1.psd website-1.1.0.psd website-2.0.psd

Slide 39

Slide 39

So we’ve solved everything? Excellent! Job done.

Slide 40

Slide 40

Many people don’t follow SemVer. :(

Slide 41

Slide 41

Common breaches Breaking changes in minor or patch New features in a patch Skipping versions Modifying a deployed package Permanent Zero

Slide 42

Slide 42

Protect yourself Lock noncompliant dependencies. Avoid confusing auto-upgrade syntax. Use shrink wrap.

Slide 43

Slide 43

Auto upgrade in NPM * auto upgrades major ^1.0.1 auto upgrades minor ~1.0.1 auto upgrades patches

Slide 44

Slide 44

x is easier to read x auto upgrades major 1.x auto upgrades minor 1.0.x auto upgrades patches

Slide 45

Slide 45

Shrink wrap Include resolved dependency tree details when you tag your project.

Slide 46

Slide 46

Why don’t people use SemVer? “Too hard to make changes” “Not followed, why bother”

Slide 47

Slide 47

Too hard to make changes? Put the user first. Plan your API. Use deprecation.

Slide 48

Slide 48

Backwards compatibility + Deprecation = Less pain for users

Slide 49

Slide 49

Revisiting our coffee API // returns coffee COFFEE.gimme({ ‘size’:’large’ }) // breaks COFFEE.gimme(‘large’) Required a 2.0.0 release.

Slide 50

Slide 50

Option: accept both // returns coffee COFFEE.gimme({ ‘size’:’large’ }) // returns coffee + warning COFFEE.gimme(‘large’) Minor release: 1.2.0

Slide 51

Slide 51

Option: different name // returns coffee COFFEE.giveMe({ ‘size’:’large’ }) // returns coffee + warning COFFEE.gimme(‘large’) Minor release: 1.2.0

Slide 52

Slide 52

Deprecation Gives you freedom Gives users time to update

Slide 53

Slide 53

Common pattern 1.2.0 feature deprecated 2.0.0 removed from docs 3.0.0 removed from code

Slide 54

Slide 54

Pre-releases + API planning = Less pain for everyone

Slide 55

Slide 55

Pre-release feedback // v1.0.0­beta.1 COFFEE.gimme(‘large’); // v1.0.0­beta.2 COFFEE.gimme(‘large’,’latte’,’skim’); // v1.0.0 COFFEE.gimme({ ‘type’: ‘latte’, ‘size’: ‘large’, ‘milk’: ‘fullcream’ })

Slide 56

Slide 56

API planning (know the domain) graphic: popchartlab.com

Slide 57

Slide 57

But… If we bump version numbers, people will think the API is unstable!

Slide 58

Slide 58

Hauptversionsnummernerhöhungsangst noun Fear of increasing the major version number

Slide 59

Slide 59

Be judicious 50.1.1 is fine 1.50.1 is great 1.1.50 is not so great

Slide 60

Slide 60

“Not followed, why bother” Lack of compliance does not invalidate standards.

Slide 61

Slide 61

Advocate. This is not just a job, it’s a craft.

Slide 62

Slide 62

Professionalism We must earn titles like ‘Engineer’ by displaying engineering rigour

Slide 63

Slide 63

This is not a new call

Slide 64

Slide 64

Professionalism API stability. Predictability. Quality.

Slide 65

Slide 65

Professionalism SemVer is a small piece. Use it. Demand it.

Slide 66

Slide 66

1.2.3 1 = broken 2 = improved 3 = fixed semver.org

Slide 67

Slide 67

1.2.3 1 = broken 2 = improved 3 = fixed semver.org Thank you. @200okpublic, command-line.net