Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Politics of JavaScript

The Politics of JavaScript

Presented at Web Directions Code, Melbourne, Australia
May 2nd 2013

NOTE for those who didn't see it live: "humble style guide" is a parody. I'm not hating on "new" and I'm certainly not advocating "always use ==="

Angus Croll

May 02, 2013
Tweet

More Decks by Angus Croll

Other Decks in Technology

Transcript

  1. ; == “I’m not sure how our community got so

    religious and fact-disoriented, but it has got to stop” “I am sorry that, instead of educating you, the leaders in this language community have given you lies and fear.” “That is insanely stupid code. Fix it now. Learn to use semicolons”
  2. “Please don’t do this” Every tech forum. Ever. “The subset

    I carved out is vastly superior to the language as a whole” Douglas Crockford - The Good Parts
  3. A: “Part of me wonders if it has more to

    do with a lack of experience (perceived or actual) with javascript coders. I can see how someone just hacking away at some sample code could make an innocent mistake with ++ and --, but I don't see why an experienced professional would avoid them.”
  4. “The body of a for in should be wrapped in

    an if statement to filter unwanted properties from the prototype”—JS Lint “hasOwnProperty [is] essential when iterating over the properties of any object ”—JS Garden
  5. Don’t buy the code for the dumbest ideology, it negates

    our responsibility to educate ourseleves, and our team. It holds us back and holds the language back.
  6. Removed all traffic lights and signs from the town's centre

    Two years after the system was introduced, average travel times lowered significantly and yearly accidents were reduced from 8 to 1. Drachten, Netherlands 2000-2001
  7. “Accidents, as well as congestion, are reduced when motorists show

    greater individual responsibility, rather than mentally switching off to behave like automata”
  8. function natcompare(a,b) { var ca, cb; while (true) { ca

    = a.charAt(ia++); cb = b.charAt(ib++); //(some zero checking goes here) if (ca == 0 && cb == 0) { //The strings compare the same. return 0; } if (ca < cb) {return -1;} if (ca > cb) {return +1;} } }
  9. function natcompare(a,b) { var ca, cb; while (true) { ca

    = a.charAt(ia++); cb = b.charAt(ib++); //(some zero checking goes here) if (ca === 0 && cb === 0) { //The strings compare the same. return 0; } if (ca < cb) {return -1;} if (ca > cb) {return +1;} } }
  10. function natcompare(a,b) { var ca, cb; while (true) { ca

    = a.charAt(ia++); cb = b.charAt(ib++); //(some zero checking goes here) if (ca === 0 && cb === 0) { //YOU ARE DOOMED!. return 0; } if (ca < cb) {return -1;} if (ca > cb) {return +1;} } }
  11. Browsers are wise to repetitious benchmarking (e.g. split) You’re better

    off profiling your real life app JSPerf is fun, but remember...
  12. These are petty pseudo-contingencies Anyone could override Object.prototype and we’d

    all be screwed Work with people and libraries that you respect
  13. “Always code as if the person who ends up maintaining

    your code is a violent psychopath who knows where you live.” - Jeff Attwood
  14. Good code doesn’t walk on eggshells Good code requires knowledge

    of your language and respect for your team Good code is bold
  15. GWT (Java) Dart (Dart) ClojureScript (Clojure) UnJavaScripty Transpilers Opal (Ruby)

    Pyjs (Python) Perlito (Perl) Script# (C#) scheme2js (Scheme) ghcjs (Haskell) Amber (Smalltalk) Go2js (Go) j2js (Java) rb2js (Ruby) rb2js (Ruby) Skuplt (Python) Java2Script (Java) FunScript (F#) JScriptSuite (.NET) ParenScript (Lisp) Clue (C) NS Basic (Basic) dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd dash sjakhd
  16. “The Oxford Comma is rubbish” “Through the window she saw

    George, a policeman, and several onlookers”
  17. Sayre’s Law “In any dispute the intensity of feeling is

    inversely proportional to the value of the issues at stake.” Charles Phillip Issawi, 1973
  18. The One True Way! JavaScript vs CoffeeScript OOP vs Functional

    Callbacks vs Promises comma-first vs comma-last
  19. My Humble Style Guide 1. Use Brackets In Conditionals 2.

    Line Break after Function Signature 3. Space after //
  20. My Humble Style Guide 1. Use Brackets In Conditionals 2.

    Line Break after Function Signature 3. Space after // 4. ALWAYS use === 5. NEVER parseInt without a radix arg 6. You SUCK if you use new Attn. Slide Viewers: this is a parody!! Text
  21. "There are indeed many ways to do the same thing

    in JS. That's one of the beauties of the language" - Peter van der Zee
  22. We can rise above the fearmongers, the ideologues and the

    absolutists... 1) Master the fundamentals: this, prototypes, coercion and scoping 2) Experiment, Play, Have Fun and Keep an Open Mind.
  23. code credits natural order comparator Copyright (C) 2005 by SCK-CEN

    (Belgian Nucleair Research Centre) Copyright (C) 2003 by Pierre-Luc Paour <[email protected]> Copyright (C) 2000 by Martin Pool <[email protected]>
  24. photo credits JUDGES: http://fitsnews.files.wordpress.com/2007/05/group-of-judges.jpg MODERN TIMES: http://www.doctormacro.com/Images/Chaplin,%20Charlie/ Annex/Annex%20-%20Chaplin,%20Charlie%20(Modern%20Times)_01.jpg DRACHTEN BEFORE:

    http://assets.knowledge.allianz.com/img/ before_laweiplein_drachten_ah_51281.jpg DRACHTEN AFTER: http://cameronwatson.co.nz/wp-content/uploads/ 2013/03/Drachten.png DICK CHENEY: http://scrapetv.com/News/News%20Pages/Politics/images-4/ cheney-evil.jpg AUTO GEAR: http://www.csa.com/discoveryguides/auto/images/res3.jpg MANUAL GEAR: http://media-social.s-msn.com/images/blogs/ 00100065-0000-0000-0000-000000000000_00000065-06d9-0000-0000-0000 00000000_20120607230629_HighGlossBlackGearShiftKnob_867.jpeg FOOD PILL: http://2.bp.blogspot.com/-411Q8hsbXjk/T0K2gN55L-I/ AAAAAAAAEQc/M2LXaIfMCxw/s1600/pill+on+a+plate.jpg FRIES: http://www.bubblews.com/assets/images/news/ 1646144206_1356758521.jpg TOOLBELT: http://image.made-in-china.com/2f0j00nMhElzuKnBrs/Double- Pouch-Tool-Belt.jpg COCKPIT: http://etc.usf.edu/clippix/pix/airplane-controls_medium.jpg NELSON MANDELA: http://theelders.org/sites/default/files/imagecache/ full_width_940x430/nelson-mandela-un-600px.jpg CHEETAHS: http://img.thesun.co.uk/multimedia/archive/01511/ WILD-532_1511437a.jpg