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

Go - A great language for building web applications

sporto
September 06, 2013
260

Go - A great language for building web applications

sporto

September 06, 2013
Tweet

Transcript

  1. Go
    Why use it for building web application?
    @sebasporto

    View Slide

  2. Comparing it to languages I use and love
    Ruby
    JavaScript

    View Slide

  3. To start with
    + Lightweight
    + Relatively easy to learn
    + Familiar

    View Slide

  4. It is fast

    View Slide

  5. Bubble sort benchmark
    #  ruby
    bubble.call([2,  10,  1,  9,  5,  6,  8,  3,  7,  4])
    //  JS
    bubble([2,  10,  1,  9,  5,  6,  8,  3,  7,  4]);
    //  Go
    arr  :=  []int{2,  10,  1,  9,  5,  6,  8,  3,  7,  4}
    bubble(arr)
    Code here

    View Slide

  6. It is fast!
    190x faster than Ruby

    View Slide

  7. Concurrency as core feature

    View Slide

  8. Concurrency - Parallel requests

    View Slide

  9. View Slide

  10. Concurrency - Parallel requests
    Ruby
    Mutex and Threads :(
    EventMachine :(

    View Slide

  11. Concurrency - Parallel requests
    Node.js
    var  defX  =  Q.defer();
    var  defY  =  Q.defer();
    var  oneAndTwo  =  Q
     .all([defX.promise,  defY.promise])
     .then(processConcat);
     
    requestValue('/x',  defX);
    requestValue('/y',  defY);

    View Slide

  12. Concurrency - Parallel requests
    Go
    var  cx  chan  string  =  make(chan  string)
    var  cy  chan  string  =  make(chan  string)
    go  requestValue("/x",  cx)
    go  requestValue("/y",  cy)
    x  :=  <-­‐cx
    y  :=  <-­‐cy
    processConcat(x,  y)

    View Slide

  13. Efficient memory usage

    View Slide

  14. #  Run  benchmark
    ab  -­‐n  10000  -­‐c  100  http://127.0.0.1:8100/
    Node.js
    FATAL  ERROR:  (...)  process  out  of  memory
    Go
    Time  taken  for  tests:      20.689  seconds
    Complete  requests:            10000
    #  No  problems

    View Slide

  15. Rich standard library
    + Http
    + Templating
    + JSON

    View Slide

  16. Static typing (+ IMO)
    + More robust
    + Easier to refactor
    + Less tests
    + Compiler can go crazy with optimisations
    + Still flexible (with interfaces)
    + No ceremony

    View Slide

  17. Compiled
    But ultra fast

    View Slide

  18. Single binary
    + Compile and deploy
    + No need to worry about dependencies, e.g. NPM modules, RubyGems

    View Slide

  19. A lot more
    + Simple and flexible object system - composition
    + Functions as first class
    + Closures
    + Standard formating of source code

    View Slide

  20. It is great alternative
    Try it!

    View Slide

  21. Thanks
    @sebasporto

    View Slide