$30 off During Our Annual Pro Sale. View Details »

Conquering a large JavaScript codebase

Conquering a large JavaScript codebase

JavaScript was originally conceived to write little scripts that could add some interactivity to a web page. Today, it is used for increasingly large applications — in the browser, but also on the server, e.g. using node.js.
Cloud9 IDE is an Integrated Development Environment developed exclusively in JavaScript, both on the client and server-side, counting over 240,000 lines of JavaScript code. Managing a code base this large requires a good architecture, good solid code foundation as well as solid tools. During this talk I will describe the Cloud9 infrastructure as well as the techniques, libraries and tools we are developing to make it scale, and also how language analysis is helping us make sure that our code is rock-solid thoughout all our application.

Sergi Mansilla

May 18, 2012
Tweet

More Decks by Sergi Mansilla

Other Decks in Programming

Transcript

  1. a large JavaScript codebase
    Conquering

    View Slide

  2. @sergimansilla

    View Slide

  3. View Slide

  4. View Slide

  5. View Slide

  6. Create
    Share Test
    Deploy
    Run/Debug

    View Slide

  7. The$easiest$way$to$create$Node.js$apps

    View Slide

  8. Ftp
    WebDAV
    Heroku
    Git
    Language Analysis
    Vim mode
    Run/Debug
    Cloud storage
    Revisions
    Search
    Collaboration
    Cloudfoundry
    Azure
    Testing
    CLI
    Bitbucket
    Plugins

    View Slide

  9. Pretty big app

    View Slide

  10. More than 1M lines
    (with semicolons)

    View Slide

  11. Of JavaScript

    View Slide

  12. Pure madness

    View Slide

  13. Why sparta madness?

    View Slide

  14. Javascript/Node.js
    make you more productive

    View Slide

  15. But they won’t help
    you through your growing pains

    View Slide

  16. What about
    some examples

    View Slide

  17. View Slide

  18. Why Node.JS?

    View Slide

  19. View Slide

  20. V8 JavaScript engine

    View Slide

  21. Bindings to libuv

    View Slide

  22. Best cross-platform I/O library

    View Slide

  23. API accessible from JavaScript

    View Slide

  24. Async I/O

    View Slide

  25. Async I/O is a big deal

    View Slide

  26. You can do things like this
    without blocking

    View Slide

  27. You can do things like this
    without blocking
    Loop$monkey,$loop!
    Write$a$‘.’$for$each$read$file
    Read$this$very$file

    View Slide

  28. View Slide

  29. You probably want
    something like this
    Read$this$very$file
    Write$a$‘.’$for$each$read$file
    Loop$monkey,$loop!
    Only$100$items$at$a$
    Dme,$thanks

    View Slide

  30. Never, ever, ever, EVER block

    View Slide

  31. View Slide

  32. In node, all APIs are
    asynchronous

    View Slide

  33. In node, all APIs are
    asynchronous?

    View Slide

  34. Getting a hash

    View Slide

  35. Getting a hash

    View Slide

  36. Getting a hash

    View Slide

  37. Getting a hash

    View Slide

  38. Profile before going live

    View Slide

  39. DTrace + node-stackvis
    http://blog.nodejs.org/2012/04/25/profiling-node-js/

    View Slide

  40. Embrace the
    paradigm

    View Slide

  41. Push processing
    to the client

    View Slide

  42. Use workers

    View Slide

  43. Use workers
    serialization < computation
    BUT only if

    View Slide

  44. Use workers
    worker.postMessage(...)
    Small objects only!

    View Slide

  45. Modularize your code

    View Slide

  46. Your application will fail

    View Slide

  47. Be prepared

    View Slide

  48. Architect
    github.com/c9/architect

    View Slide

  49. “A simple yet powerful plugin
    system for large-scale node
    applications”

    View Slide

  50. Isolation

    View Slide

  51. Security

    View Slide

  52. Providers / Consumers

    View Slide

  53. Advanced IPC
    between processes

    View Slide

  54. Sourcemint
    github.com/sourcemint/sm-npm

    View Slide

  55. Package manager that wraps
    package managers

    View Slide

  56. Understands any kind
    of dependency
    (npm, pip, git, zip...)

    View Slide

  57. Easy edit/publish

    View Slide

  58. Tooling matters

    View Slide

  59. Normal developers

    View Slide

  60. JavaScript Developer

    View Slide

  61. View Slide

  62. Tooling matters

    View Slide

  63. Tooling matters
    especially for JavaScript

    View Slide

  64. View Slide

  65. Use the power of...

    View Slide

  66. tatic

    View Slide

  67. program analysis

    View Slide

  68. View Slide

  69. Iterating using undeclared
    variable

    View Slide

  70. Warning: you are in an anonymous inner function
    with its own “this” pointer

    View Slide

  71. Did you mean length?

    View Slide

  72. “The most important thing I have done as
    a programmer in recent years is to
    aggressively pursue static code
    analysis.”
    John Carmack

    View Slide

  73. treehugger.js
    github.com/ajaxorg/treehugger

    View Slide

  74. “The jQuery of AST analysis.”

    View Slide

  75. What can you do with it?

    View Slide

  76. Low-level tooling

    View Slide

  77. Intelligent code completion

    View Slide

  78. Complex refactoring

    View Slide

  79. Automate everything

    View Slide

  80. Human error happens

    View Slide

  81. Human error happens
    ALL THE TIME

    View Slide

  82. Spend time on
    automation scripts

    View Slide

  83. Spend time on
    automation scripts
    It really pays off

    View Slide

  84. Happy coding!

    View Slide

  85. Questions?

    View Slide

  86. http://github.com/sergi
    @sergimansilla
    http://c9.io

    View Slide