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

Your Code Sucks: Best Practices for Enterprise ...

Arthur Kay
August 15, 2012

Your Code Sucks: Best Practices for Enterprise JavaScript Development

From ThatConference 2012

Arthur Kay

August 15, 2012
Tweet

More Decks by Arthur Kay

Other Decks in Programming

Transcript

  1. WHO AM I? •  Arthur Kay •  Solutions Engineer @

    Sencha, Inc. •  Web Development ~15 years •  www.akawebdesign.com •  @arthurakay
  2. AGENDA •  Improving application performance •  Increasing code stability • 

    Scaling applications for enterprise •  Tools •  Advice
  3. DO THIS INSTEAD •  Cache values (references) •  Avoid using

    document.getElementById() and other global queries
  4. DO THIS INSTEAD •  Organize your file system •  Files

    and folders should match namespacing •  MVC (or something) •  Development loader / Production builder
  5. DO THIS INSTEAD •  Descriptive names on everything (except iterators)

    •  Common naming conventions (camelCase vs TitleCase vs nocase) •  Exceptions for •  constants ( SOME_CONSTANT ) •  constructors ( MyClass ) •  sub-namespaces ( Foo.bar.Class )_
  6. DO THIS INSTEAD •  Comment top-level structures •  Add notes

    whenever logic is not obvious •  Build your docs into a searchable tool
  7. DO THIS INSTEAD •  Abstraction! •  Use mixins when possible

    •  Apply stuff to prototypes •  Have similar classes/methods? •  call() and apply()
  8. DO THIS INSTEAD •  Keep methods under 50 lines • 

    Keep files under 500 lines •  Use as much whitespace as possible.
  9. DO THIS INSTEAD •  Write “testable” code •  Focus on

    important / trouble areas •  AUTOMATE UNIT TESTING •  Don’t insist on UI (integration/iteraction) tests * Test Driven JavaScript Development by Christian Johansen
  10. IDE

  11. ADDITIONAL RESOURCES •  “Maintainable JavaScript” by Nicholas Zakas •  http://www.slideshare.net/nzakas/maintainable-javascript-2012

    •  “Code Conventions for JS” by Douglass Crockford •  http://javascript.crockford.com/code.html •  “JavaScript Performance Tips & Tricks” by Grgur Grisogono •  http://moduscreate.com/javascript-performance-tips-tricks/