git ssb

0+

dinoworm πŸ› / campjs-viii-ludditejs



Tree:
πŸ“„.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
README.md

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:


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:

  1. if a file called some_module.js exists in the current folder node will load that, otherwise:
  2. node looks in the current folder for a node_modules folder with a some_module folder in it
  3. 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 find some_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 value
  • thing.set(...) sets the value
  • thing(function (value) { ... }) listens to the value.

stream


references

???

TODO luddite.js apps:

Built with git-ssb-web