Gleb Bahmutov PRO
JavaScript ninja, image processing expert, software quality fanatic
Dr. Gleb Bahmutov PhD
Kensho Boston / NYC
Does your code look like this?
There is a better way
Code out of control: red flags
Divide and conquer
Tools and semantic versioning rants
Build time > 15 seconds
Multiple tools, environments
Impossible to unit test a feature
You have to use AND to describe the project and its goals
Source control to built and tested > 10 minutes
No code reuse
Giving up
var sum = add(a, b);
4 variables (a, b, add and sum)
4 * (4 - 1) / 2 = 6 interactions
"Thinking, Fast and Slow" by Daniel Kahneman
function add(a, b) { ... }
var sum = add(2, 3);
console.log('2 + 3 =', sum);
// function signature
function add(a, b) { ... }
// package.json
{
"name": "my-utils",
"version": "2.0.1",
"main": "index.js"
"dependencies": {
"module-a": "1.0.0",
"module-b": "0.1.0"
}
}
// good
var a = require('another-module');
// avoid
var a = require(
'./node_modules/another-module/src/something.js');
built separately
tested separately
has SKU number
shipped to the auto plant
placed into the car
12 Factor App (from Heroku)
npm search colors
npm info chalk
npm home chalk
npm install chalk --save
// index.js
require('chalk');
console.log( chalk.blue('Hello world!') );
{
"name": "my-module",
"version": "0.1.0",
"git": ...,
"dependencies": {
"foo": "0.1.*",
"bar": "~1.2.0",
"baz": "^2.0.1"
},
"devDependencies": {
"grunt-concat": "0.1.1"
}
}
$ npm config set save-exact true
$ npm install --save-exact grunt-nice-package
// cleans up fuzzy symbols
// dependencies-resolution uses module-a@2.0.0, module-b@0.6.0
// module-b@0.6.0 uses module-a@1.0.0
$ npm list
dependencies-resolution@0.0.0
├── module-a@2.0.0
└─┬ module-b@0.6.0
└── module-a@1.0.0
1.5.0
4.0.1
0.1.0
2.2.0
2.2.0
0.1.0
0.1.0
2.2.0
2.2.0
0.1.0
0.1.1
0.1.2
2.2.1
2.2.2
2.5.0
3.0.0
3.0.1
// package.json
{
"dependencies": {
"module-a": "1.0.0"
}
}
// npm registry:
module-a: 0.8.0, 0.9.0, 1.0.0, 1.0.1, 2.0.0
// package.json
{
"dependencies": {
"module-a": "1.0.0"
}
}
// npm registry:
module-a: 0.8.0, 0.9.0, 1.0.0, 1.0.1, 2.0.0
// package.json
{
"dependencies": {
"module-a": "1.0.0"
}
}
// npm registry:
module-a: 0.8.0, 0.9.0, 1.0.0, 1.0.1, 2.0.0
function add(a, b) { ... }
...
... add(2, 3);
....
add(-1, 100);
...
...
console.log(add(0, 0));
...
function add(a, b) { XXX }
...
... add(2, 3);
....
add(-1, 100);
...
...
console.log(add(0, 0));
...
function add(a, b) { XXX }
...
... add(2, 3);
....
add(-1, 100);
...
...
console.log(add(0, 0));
...
function add(a, b) { XXX }
...
... add(2, 3);
....
add(-1, 100);
...
...
console.log(add(0, 0));
...
Hard to improve "add" AND keep everything working
// package.json "add": "1.0.0"
var add = require('add');
...
... add(2, 3);
....
add(-1, 100);
...
...
console.log(add(0, 0));
// module ADD@1.0.0
function add(a, b) { ... }
// package.json "add": "1.0.0"
var add = require('add');
...
... add(2, 3);
....
add(-1, 100);
...
...
console.log(add(0, 0));
// module ADD@1.1.0
function add(a, b) { XXX }
// package.json "add": "1.1.0"
var add = require('add');
...
... add(2, 3);
....
add(-1, 100);
...
...
console.log(add(0, 0));
// module ADD@1.1.0
function add(a, b) { XXX }
// package.json "add": "1.0.0"
var add = require('add');
...
... add(2, 3);
....
add(-1, 100);
...
...
console.log(add(0, 0));
// module ADD@1.1.0
function add(a, b) { XXX }
type from to successful %
patch 0.2.0 0.2.1 100
patch 0.4.0 0.4.1 100
patch 0.6.0 0.6.1 100
patch 0.6.4 0.6.5 100
minor 0.6.5 0.7.0 100
major 0.8.1 1.0.0 0
minor 1.0.0 1.1.0 100
patch 1.1.0 1.1.1 94
minor 1.1.1 1.2.0 100
patch 1.2.0 1.2.1 100
minor 1.2.1 1.3.0 100
patch 1.3.0 1.3.1 100
patch 1.3.1 1.3.2 100
minor 1.3.2 1.4.0 100
* Ramda is still 0.15.0 (< 1.0.0)
We fail to follow SemVer – and why it needn’t matter by Stephen Bonnemann (JSConf Budapest 2015)
rant
rant
We fail to follow SemVer – and why it needn’t matter by Stephen Bonnemann (JSConf Budapest 2015)
Test each code against its own
previous tests
Single huge project - lots of small projects
Dr. Gleb Bahmutov PhD
Kensho Boston / NYC
Companion blog posts: Dependencies for NodeJs, modular development
By Gleb Bahmutov
Any JavaScript project requires 3rd party modules. As soon as you depend on specific versions, your module falls behind. I will show how to keep your software up to date without any effort (as long as there are some tests). You can automatically upgrade dependencies for an individual project, a collection of projects. You can even see the anonymous version upgrade results across the public projects around the world to judge if a particular update is likely to succeed. What about projects that depend on your software? Before releasing a new version, you can test some or all of your dependencies against the new code.
JavaScript ninja, image processing expert, software quality fanatic