Best practices for JavaScript RIAs


Published on

Published in: Technology

Best practices for JavaScript RIAs

  1. 1. Best practices for JavaScript RIAs Carlos Ble | | @carlosble Thanks to January 2013
  2. 2. Know the history
  3. 3. Table of contents● Is it an application or is it a website?● Is it a library, a framework, or application code?● Am I test-driving the code or not?● Testing tools● Testing techniques● Design patterns and architecture● Client-Sever?
  4. 4. What kind of JavaScript are you writing?● For frameworks and libraries:       if (someVariable === undefined)...● For applications, without automated tests:● Test-first JavaScript:   if (someVariable)...   - Duck typing is OK. - No need for lots of JavaScript patterns. - Write code for humans. Functional or Object Oriented? Just make it SOLID●
  5. 5. TDD with JavaScript●●
  6. 6. Testing toolsThere are new tools every day! Some tools I use, thanks to @pasku1 & @eamodeorubio(follow these guys): Jasmine/Mocha Jasmine-node Chai – CasperJS / PhantomJS JsTestDriver Believe me, tools are there to support concepts,they are not important themselves!
  7. 7. Testing Rules & Test-First Rules● Test-first is absolutely different from testing.● Do not mock artifacts you dont own.● Use stubs for queries and mocks/spies for actions.● Exploratory testing is always necessary.
  8. 8. Widgets are objects, not pictures    
  9. 9. Events: DOM level 0 – Traditional model (one2one: a nice kind of dependency injection)     Events: Observer (one2many) & Pub/Sub (many2many)
  10. 10. Passive View
  11. 11. Factory Singleton     More patterns:
  12. 12. Optimal code for machines is hard to read for humans● Dont write code for machines, write it for humans● Do you really have performance metrics?● Google Closure Compiler● CoffeeScript● Do performance testing often
  13. 13. Smart client, dumb server● Let the client side application contain all the businesslogic you can.● Keep the server just as an event bus for clients tointeract with each other.● Examples: - TeamMonitor in - Skype and TeamViewer clients can connect directlybetween them (OK, this is not JavaScript).● Advantages: - Ease of testing. - Ease of maintenance. - Scalability.
  14. 14. Sample app: LiveTeamApp
  15. 15. Conclusions● JavaScript is too big. Consider the context to makedecisions.● Retrieve best practices from the desktop developmentage, those days back in the 90s.● Read books, the good ones dont get old.● Try to understand the concepts, not just the tools.● You usually dont need frameworks you need libraries.● Care about your code and your tests . Test-driveyour code.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.