Lessons from a coding veteran - Web Directions @MediaPresentation Transcript
LESSONS FROM A CODING VETERAN
TOM HUGHES-CROUCHER @sh1mmer
Stuff to be “proud of ”BSc 1st Class (Hons) Computer Scalable Server-Side Code with JavaScriptScienceHelped write two W3C standardsWritten code for: NASA Tesco Channel 4 Node Up and Running Three Telecom Tom Hughes-Croucher Yahoo!
3 RULES TO LIVE BY
RULE 1.COMPLEXITY IS THE ENEMY
WHAT IS COMPLEXITY?
COMPLEXITY IS...
...TOO MANY FEATURES
...UNINTELLIGIBLE CODE
...CODE THAT DOES THINGS MORE THAN ONE WAY
...TOOMUCHCODETHATJUSTGOESONANDONANDRUNSTOGETHER
COMPLEXITY IS...
...ANYTHING THATREDUCES UNDERSTANDING
WHY IS UNDERSTANDING SO IMPORTANT?
“BUILD TWITTER”
What is Twitter?140 character micro-blogging serviceAJAX web siteAPIScalability (sort of)etc
“BUILD TWITTER” IS NOT UNDERSTANDABLE
COMPUTERS REQUIREPERFECT INSTRUCTIONS
PERFECTION REQUIRES UNDERSTANDING
RULE 1A.HAVE A CLEAR GOAL
TANGIBLE OBJECTIVE
IT IS YOUR JOB AS DEVELOPERTO ACCEPT THE REQUIREMENTS
CLEAR OUTCOME
SUCCESS = ??
A WAY TO MEASURE SUCCESS
TDD
PUBLIC API
AGILE ALLOWS YOU TO FAIL FAST
FAILING FAST ALLOWSREDUCE COST OF DEFINITION
RULE 1B.WRITE CODE YOU* CAN UNDERSTAND * and your team
function(a,b,c){return{pub:function(d,e){for(c in a)if(c.split("-")[0]==d)a[c](e)!==!1||delete a[c]},sub:function(d,e){a[d+--b]=e}}}({},0)
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.)
LIKE “REAL” CODE
TERSE != BETTER
LANGUAGES ARE EXPRESSIVE
//this is JavaScriptvar isTrueif (true) { isTrue = true}
Summary1. Complexity is the enemy 2. Dont optimise too soon1a. Have a clear goal 2a. 1st draft, 2nd draft1b. Write code you can 2b. rewriting code to be moreunderstand complex is ok when you understand it1c. Pick some conventions 2c. Document the heck out of1d. Use abstraction wisely optimisations 2d. optimise with tools if possible