O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

NodeJS, CoffeeScript & Real-time Web

8.958 visualizações

Publicada em

Publicada em: Tecnologia
  • Seja o primeiro a comentar

NodeJS, CoffeeScript & Real-time Web

  1. 1. Node.js, CoffeeScript & Real-Time Web Jakub Nesetril jakub@apiary.io @jakubnesetrilčtvrtek, 30. června 2011
  2. 2. About Me web developer for 15 years director of frontend engineering, GoodData CEO/founder of apiary.io - hosted REST API toolsčtvrtek, 30. června 2011
  3. 3. Contents not a deep-dive aims to explain a bit of the frenzy really more about Javascriptčtvrtek, 30. června 2011
  4. 4. čtvrtek, 30. června 2011
  5. 5. What is Node.js • it’s NOT a framework: but several Rails/Sinatra-style frameworks are available for it • it’s not a programming language: uses Javascript • it’s not a VM: uses Chrome’s v8 engine)čtvrtek, 30. června 2011
  6. 6. What is Node.js • clever glue code between C and Javascript, with standard libraries • exposes low-level POSIX to JS • advanced TCP/HTTP support • strongly event-oriented (reactor pattern) • fastčtvrtek, 30. června 2011
  7. 7. Popular #3 on Github more traffic then jQueryčtvrtek, 30. června 2011
  8. 8. Getting Started—installing Node Node changes quickly, use nvm or n to install: https://github.com/creationix/nvm https://github.com/visionmedia/n Allows to quickly migrate between version: $ nvm ls … stable: v0.4.8-rc latest: v0.4.8-rc current: v0.4.6 $ nvm install 0.4.8-rc »»» downloads, builds, installs and sym-links new nodečtvrtek, 30. června 2011
  9. 9. Getting Started—installing libraries NPM - Node Package Manager $ curl http://npmjs.org/install.sh | sh … $ npm install foo Debugging: $ npm install -g node-inspector $ npm install v8-profiler interactive debugger, breakpoints, inspection of stack variables, memory snapshosts, cpu profiling…čtvrtek, 30. června 2011
  10. 10. Getting Started—working Node loads code at startup Restart required when code changes (unlike PHP, similar to Ruby) $ npm install -g supervisor Supervisor watches/restarts your app when changed: $ supervisor --watch . server.js … DEBUG: crashing child DEBUG: Starting child process with node server.js …čtvrtek, 30. června 2011
  11. 11. Demočtvrtek, 30. června 2011
  12. 12. Javascriptčtvrtek, 30. června 2011
  13. 13. Javascriptčtvrtek, 30. června 2011
  14. 14. “The Worlds Most Misunderstood Programming Language” Douglas Crockford, the Yoda of Javascriptčtvrtek, 30. června 2011
  15. 15. čtvrtek, 30. června 2011
  16. 16. Javascript as a Compilation Target GWT (Google), ObjectiveJ (Cappuccino/280North), everything else… Different idioms then Javascript Obscure integration with other Javascript Unreadable output: function g(){var a=G(db);if(a!=null){return a}return Q} function i(){var a;if(typeof isBodyLoaded==gb||! isBodyLoaded()){var b=hb;var c;n.write(ib+b +jb);c=n.getElementById(b);a=c&&c.previousSibling;while (a&&a.tagName!=kb){a=a.previousSibling}if(c) {c.parentNode.removeChild(c)}if(a&&a.src){return e (a.src)}}return Q}čtvrtek, 30. června 2011
  17. 17. čtvrtek, 30. června 2011
  18. 18. Compiles to clean Javascriptčtvrtek, 30. června 2011
  19. 19. CoffeeScript Exposes only The Good Parts™ of Javascript Syntactic sugar = Less noise, more readable output Somewhere between Python and Ruby: • whitespace/indentation defines blocks • classes! inheritance! • default arguments, splats… (catch-all argument) • list comprehensions • destructuring assignments (pattern matching) • auto local-scoped variables (no more manual var) • optional binding of this scope • and many more…čtvrtek, 30. června 2011
  20. 20. Popular CoffeeScript plan CoffeeScript JavaScript 25% 63% 12% Hacker News Poll, June 22nd http://news.ycombinator.com/item?id=2683372čtvrtek, 30. června 2011
  21. 21. Getting Started—installing $ npm install -g coffee-script $ coffee server.coffee $ coffee --compile server.coffee »» produces server.js $ coffee coffee>čtvrtek, 30. června 2011
  22. 22. Common Problems you’ll end up debugging in Javascript, know how stuff compiles! isnt is not is not console.log(1 isnt false) console.log(1 is not false) in vs of console.log(x) for x in {a: “a”, b: “b”} console.log(x) for x of {a: “a”, b: “b”} tricky local vs. global variable scopečtvrtek, 30. června 2011
  23. 23. Real-Time Webčtvrtek, 30. června 2011
  24. 24. Traditional Model Request/Response The way HTTP was designed Dramatic benefits for scaling and simplicityčtvrtek, 30. června 2011
  25. 25. Real-Time Web Needs bi-directional communication (polling too slow) WebSocket standard in process, varying support in new browsers Older browsers can use flash fallback or “long-polling” mechanisms Requires support from ground-up across the whole backend stack (proxies, web servers, application servers)čtvrtek, 30. června 2011
  26. 26. Solutions • Pusher (WebSocket IaaS) similar to Apple iOS push notification service keep your existing code/infrastructure send HTTP POST request to Pusher to push messages • socket.io $ npm install socket.io implements websocket server AND client transparently supports all fallback mechanisms (many!) supports IE5.5+, WebKit on iOS/Android/WebOSčtvrtek, 30. června 2011
  27. 27. Demosčtvrtek, 30. června 2011
  28. 28. Questions?čtvrtek, 30. června 2011
  29. 29. Thanks! @jakubnesetril http://apiary.io/čtvrtek, 30. června 2011

×