• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Functional node.js

on

  • 7,660 views

 

Statistics

Views

Total Views
7,660
Views on SlideShare
7,646
Embed Views
14

Actions

Likes
5
Downloads
46
Comments
0

2 Embeds 14

http://paper.li 13
https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Functional node.js Functional node.js Presentation Transcript

    • Functional Node.js
      Making things simple
      By Robert Roose
    • Who am I?
    • Understanding the world’s most misunderstood programming language
    • Programming
      religion
      -noun. a set of beliefs concerning the cause, nature, and purpose of code, which guide programmers through the creation of software, usually involving devotional and ritual observations and/or gatherings, and often containing standards governing the style of development practices
    • Functional programming
      Advantages
      Terse
      Clarity
      Easier maintainability
      Encourages immutability
      Forces better designs
      Better testability
      Less bugs
    • Functional programming
      Disadvantages
      Difficult to design
      Difficult to visualize
      Hard for the inexperiencedunenlightened
      Generally slower
    • Common misunderstanding
      Functional programming: it’s just for those academic types
    • Common misunderstanding
      Functional programming: it’s fun, but it doesn’t make money
    • Learning functional programming
      It makes you a better programmer
      It’s an alternative perspective of how to describe good software design
    • Agreeable points
      OOP is bad
      Side effects are evil
      Immutability is good
      Less code means less bugs
    • Pure functional programming is unpractical
      Not everything can be side effect free
      Limitations in languages, tools, OSs…
      Bureaucracy keeps things complicated
      Not everyone follows the same religion
      Businesses aren’t about pretty math problems
    • Enough with purity, let’s get back to business
      Less code
      Less buggy code
      Happier customers
      Cheaper code
      Easier maintainability
      Quicker development
      Once developers know the ropes
    • What is
      ?
    • Evented I/O framework for the V8 JavaScript engine
    • Huh?
    • Takes JavaScript beyond the browser
    • Hello Node.js!
    • So?
      Provides an easy way to build scalable network programs
      Generally fast
      Great at concurrency
      Asynchronous everything
      Almost never blocks
    • What is it good for?
      Web applications
      Especially real-time web apps
      Network applications
      Distributed systems
      General purpose applications
    • In node, everything runs in parallel, except your code
    • Single-threaded event loop
    • Traditional I/O
      Something isn’t right here…
    • But there’s only one thread
    • Scalability
      Use processes!
      Easily scale across distributed systems
      Much safer than threads
      No need to worry about states
      Use load balancer to distribute work
      HAProxy
      nginx
      multi-node
    • Why is this good?
      Simple designs
      Efficient applications
      High concurrency
      Blazingly fast for end users
    • Back to JavaScript
    • It’s just a misunderstanding…
      Dynamic, weakly typed multi-paradigm scripting language
      Prototype-based
      Functional
      Imperative
      Lisp in C’s clothing
    • It’s just a misunderstanding…
      Lots of design errors
      Lots of implementation errors
      Lots of bad books
      Lots of amateurs
    • Is it Object-Oriented?
      No, but it can be forced
      It’s prototype-based
      It has objects, but not classes
      It doesn’t have class-oriented inheritance – it has prototype-oriented inheritance
      There are lots of different ways to achieve the same thing
      Really depends on your religion
    • Is it functional?
      It supports the concepts of functional programming
      Certainly not pure
      More functional than object-oriented
      Again, it depends on your religion
    • Bad JavaScript
    • JavaScript closures
    • As good is it gets
    • Anonymous functions
    • JavaScript as a functional language
      Treat variables as constants
      Think of everything as immutable
      Don’t rely on side effects
      Avoid confusion
      Return a new object instead of modifying
      Can be used as a (non-pure) functional language
      Just use what works
    • JavaScript/Node Functional Libraries
      Underscore.js
      Utility-belt JavaScript library
      wu.js
      For laziness
      node-utils
      (plug)
    • Underscore.js
    • Async hell
    • Async hell
      starting
      reading file1.txt
      got file1.txt
      reading file2.txt
      got file2.txt
      reading file3.txt
      got file3.txt
      getting google
      got google
      ...
      File 1, File 2, File 3, 3bb0f168fbf8c9b0324cbf2fea1266ea
    • A better solution
    • A better solution
      starting
      reading file1.txt
      reading file2.txt
      reading file3.txt
      getting google
      got file1.txt
      got file2.txt
      got file3.txt
      got google
      ...
      File 1, File 2, File 3, ba5eaf36ca6e688d33ff53a466de01e1
    • Observer pattern
    • Observer pattern
      starting
      reading file1.txt
      reading file2.txt
      reading file3.txt
      getting google
      got file1.txt
      got file2.txt
      got file3.txt
      got google
      ...
      File 1, File 2, File 3, 065b003da0d66b14924086c8c8a1d7a6
    • CoffeeScript
      Attempt to expose the good parts of JavaScript
      It’s just JavaScript
      Compiles one-to-one into the equivalent JavaScript
      Makes JavaScript simpler
    • CoffeeScriptasync
    • CoffeeScriptasync
      starting
      reading file1.txt
      reading file2.txt
      reading file3.txt
      getting google
      got file1.txt
      got file2.txt
      got file3.txt
      got google
      ...
      File 1, File 2, File 3, 3290579989c493c338dcf52327442c10
    • Time for some examples
      scale-example
      comet-example
    • Only just scratched the surface
    • Resources
      JavaScript
      JavaScript: The World’s Most Misunderstood Programming Language
      The Little JavaScripter
      JavaScript as a Functional Language
      Higher-Order JavaScript
      Functional Programming – Eloquent JavaScript
      Douglas Crockford
    • Resources
      Node.js
      How to Node
      Node Documentation
      Understanding node.js
      Combined benchmark
      Ryan Dahl
    • Resources
      CoffeeScript
      CoffeeScript Site
    • Resources
      Functional Programming
      Functional Programming Doesn't Work (and what to do about)
      Why functional programming doesn't catch on
    • Questions?
    • Robert Roose
      http://twitter.com/summatix
      http://www.robertroose.info/
      http://bitbucket.org/summatix
      https://github.com/summatix
      http://bitbucket.org/shivercube
      https://github.com/shivercube