4. Stuff to be “proud of ”
BSc 1st Class (Hons) Computer Scalable Server-Side Code with JavaScript
Science
Helped write two W3C standards
Written code for:
NASA
Tesco
Channel 4
Node Up and Running
Three Telecom
Tom Hughes-Croucher
Yahoo!
33. function(
a, // the subscription object
b, // the current event number
c // (placeholder)
){
return { // return an object, with
pub: function( // a "pub" function that takes
d, // a channel name and
e // a message value,
){ // and
for( // for each
c // subscriber
in a // in the subscription object,
) if ( // if
c // its name, with the event number discarded
.split // by splitting it
("-") // with a hyphen and
[0] // taking only the first part,
== d // is equal to the published channel
) a[c](e) // call the subscriber. and if
!== !1 || // the value returned is false
delete a[c] // unsubscribe by removing the subscriber, and
},
sub: function( // a "sub" function that takes
d, // a channel name and
e // a subscriber function
){ // and,
a[ // on the subscriptions object,
d + // sets the name of the channel appended with
--b // a hyphen and the decremented event number, to
] = e // the function passed.
}
}
}( // auto-run with
{}, // the subscription object
0 // and event id.
)
66. //node.js style JavaScript
query = mysql.query('SELECT * FROM data');
query.on(‘result’, function(result) {
for(var i=0;i<length;i++) {
var row = result.rows[i];
//do something with the row
}
});
67. //threaded style JavaScript
result = mysql.query('SELECT * FROM data');
for(var i=0;i<length;i++) {
var row = result.rows[i];
//do something with the row
}
68. var x = "I am a string"
~1ns Running 1 instruction
2ns Data from l1 cpu cache
5ns Data from l2 cpu cache
80ns Data from ram
140. Summary
1. Complexity is the enemy 2. Don't optimise too soon
1a. Have a clear goal 2a. 1st draft, 2nd draft
1b. Write code you can 2b. rewriting code to be more
understand complex is ok when you
understand it
1c. Pick some conventions
2c. Document the heck out of
1d. Use abstraction wisely optimisations
2d. optimise with tools if
possible