π | .gitignore |
π | LICENSE |
π | NOTES.md |
π | README.md |
π | avatar.png |
π | dist |
π | enspiral.png |
π | example.js |
π | index.css |
π | index.html |
π | index.js |
π | package-lock.json |
π | package.json |
π | stuff |
π | test |
luddite.js
hey CampJS VIII
i'm Mikey (@ahdinosaur) from Enspiral
<div class="row">
<a href="http://dinosaur.is.com">
<img alt="Mikey's avatar" src="./avatar.png" width="200" />
</a>
<a href="http://enspiral.com">
<img alt="Enspiral logo" src="./enspiral.png" width="200" />
</a>
</div>
slides are available at http://dinosaur.is/campjs-viii-ludditejs.
???
second time presenting at a conference.
apologies in advance if i disguise any opinions as facts.
what?
this talk is a mashup of a few topics:
- why you only need simple functions and objects to build complex systems
- why the best modules should not have any added sugar
- how "mad science" led to the success of Node.js and thus JavaScript
- why TC39 (the committee behind ES6+) is bad for JavaScript
- why you should ignore "modern JavaScript" (promises, classes,
async
/await
, generators, and beyond).
first, some simplified history...,
2009
nobody cares about JavaScript
it's a toy language
Ryan Dahl (@ry) creates Node.js
watch the original presentation
To provide a purely evented, non-blocking infrastructure to script highly concurrent programs.
(original website here)
???
// core-less node? https://github.com/nodejs/node/issues/7098
// https://github.com/nucleus-js/design
function
function (...args) {
return value
}
module
here's the CommonJS module system, as used and popularized by Node.js
// cat.js
require('cat-names').random
// cat-loop.js
const cat = require('./cat')
setInterval(() => {
console.log(cat())
})
the module wrapper
every module is actually wrapped in a closure
(function (exports, require, module, __filename, __dirname) {
// your module code actually lives in here
})
how require works
When you call
require('some_module')
in node here is what happens:
- if a file called
some_module.js
exists in the current folder node will load that, otherwise:- node looks in the current folder for a
node_modules
folder with asome_module
folder in it- if it doesn't find it, it will go up one folder and repeat step 2
This cycle repeats until node reaches the root folder of the filesystem, at which point it will then check any global module folders (e.g.
/usr/local/node_modules
on Mac OS) and if it still doesn't findsome_module
it will throw an exception.
the Node aesthetic
- Callback austerity: Simplicity, asyncronous nature and nice additions that are included like the event system.
- Limited surface area: Using modules instead of extending them, NPM, re-usable interfaces and simple, consistent function calls.
- Batteries not included: Only few modules in the core distribution β reduces clutter, version dependencies and bureaucracy.
- Radical reusability: Breaking up a problem in small pieces, NPM module locations, great versioning approach
factory
βThe problem with object-oriented languages is theyβve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.β ~ Joe Armstrong
???
TODO two ways of handling errors: throw err and cb(err) how it's important to throw 'programmer errors'
callback
continuable
a "continuable" is a function that takes a single argument, a node-style (error-1st) callback.
const continuable = (cb) => {
// do stuff...
cb(err, data)
}
observable
thing()
gets the valuething.set(...)
sets the valuething(function (value) { ... })
listens to the value.
stream
references
???
TODO luddite.js apps:
Built with git-ssb-web