How To Read Code PDF
How To Read Code PDF
Aria Stewart
@aredridel
I almost didn't give this talk.
What do we mean when we say "reading
source code"?
Reading for comprehension
... to find bugs
... to find interactions
... to review
... to see the interface
... to learn!
Reading isn't linear
Reading Order
function EventEmitter() { }
exports.EventEmitter = EventEmitter;
// Allow the Location class to cancel the router setup while it refreshes
// the page
if (get(location, 'cancelRouterSetup')) {
return;
}
this._setupRouter(router, location);
container.register('view:default', _MetamorphView);
container.register('view:toplevel', EmberView.extend());
location.onUpdateURL(function(url) {
self.handleURL(url);
});
From Ember.Router
Process entailment
r.symbols.forEach(function(s, i) {
var symNo = out.indexOf(s.name);
if (!~out.indexOf(s.name)) {
symNo = out.length;
out.push(s.name);
}
r.symbols[i] = symNo;
});
r.sym = out.indexOf(r.name);
});
return out;
}
rules.symbols = censusSymbols();
Configuration
app.configure('production', 'staging', function() {
app.enable('emails');
});
app.configure('test', function() {
app.disable('emails');
});
An example using Javascript for configuration.
"express": {
"env": "", // NOTE: `env` is managed by the framework. This value will be overwritten.
"x-powered-by": false,
"views": "path:./views",
"mountpath": "/"
},
"middleware": {
"compress": {
"enabled": false,
"priority": 10,
"module": "compression"
},
"favicon": {
"enabled": false,
"priority": 30,
"module": {
"name": "serve-favicon",
"arguments": [ "resolve:kraken-js/public/favicon.ico" ]
}
},
standard -F dc.js
DuplexCombination.prototype.on = function (ev, fn) {
switch (ev) {
case 'data':
case 'end':
case 'readable':
this.reader.on(ev, fn)
return this
case 'drain':
case 'finish':
this.writer.on(ev, fn)
return this
default:
return Duplex.prototype.on.call(this, ev, fn)
}
}
arg = arg || {}
Default to an empty object.
arg = (arg == null ? true : arg)
Default to true only if a value wasn't explicitly passed.
Look for layers
req and res from Express are tied to the web; how deep do
they go?
Is there an interface boundary you can find?
Look for tracing
map.
reduce.
cross-join.
It's time to go read some source code.
Enjoy!