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

Tower of Babel: A tour of programming languages

Tower of Babel: A tour of programming languages

A tour of 7 programming languages: Ruby, JS, CoffeeScript, Objective-C, Go, Clojure and Scala.

Matt Aimonetti

September 28, 2012
Tweet

More Decks by Matt Aimonetti

Other Decks in Programming

Transcript

  1. @merbist
    tower of babel
    A tour of programming languages
    Sunday, October 21, 12

    View Slide

  2. matt aimonetti
    @merbist
    http://matt.aimonetti.net
    http://github.com/mattetti
    Sunday, October 21, 12

    View Slide

  3. title sub
    title
    conf - Matt Aimonetti - @merbist
    now hiring
    Sunday, October 21, 12

    View Slide

  4. Human Languages
    studied by linguists
    Sunday, October 21, 12

    View Slide

  5. Sapir-Whorf
    Hypothesis
    linguistic differences have consequences
    on human cognition and behavior
    The principle of linguistic relativity holds that the
    structure of a language affects the ways in which its
    speakers conceptualize their world, i.e. their world
    view, or otherwise influences their cognitive
    processes.
    Sunday, October 21, 12

    View Slide

  6. Sunday, October 21, 12

    View Slide

  7. interpreted compiled
    dynamically
    typed
    statically
    typed
    object
    oriented
    functional difficulty
    JavaScript X X X* X easy
    Ruby/Python X X X X normal
    CoffeeScript X X X X normal
    Objective-C X X X X * nightmare
    Java X X X hard
    Go X *
    structural
    X X* X normal
    Clojure X X (hints)
    * X normal/
    nightmare/
    hell
    Scala X *
    structural
    X
    inferred
    X X normal/
    nightmare
    Sunday, October 21, 12

    View Slide

  8. All Garbage
    Collected
    -
    Automatic memory
    management
    Sunday, October 21, 12

    View Slide

  9. Interpreted
    vs
    Compiled
    Sunday, October 21, 12

    View Slide

  10. Dynamically
    vs
    Statically
    Typed
    Sunday, October 21, 12

    View Slide

  11. Object Oriented
    vs
    not OO
    Sunday, October 21, 12

    View Slide

  12. Functional
    Programming
    vs
    not FP
    Sunday, October 21, 12

    View Slide

  13. don’t judge a
    language based on
    Sunday, October 21, 12

    View Slide

  14. Hello World
    Sunday, October 21, 12

    View Slide

  15. Syntax
    Sunday, October 21, 12

    View Slide

  16. Understand
    each
    language’s
    philosophy
    Sunday, October 21, 12

    View Slide

  17. Know
    each
    language’s
    strong point
    Sunday, October 21, 12

    View Slide

  18. Sunday, October 21, 12

    View Slide

  19. Pick your interest
    Sunday, October 21, 12

    View Slide

  20. Sunday, October 21, 12

    View Slide

  21. Sunday, October 21, 12

    View Slide

  22. Sunday, October 21, 12

    View Slide

  23. Sunday, October 21, 12

    View Slide

  24. Ruby
    Sunday, October 21, 12

    View Slide

  25. Interpreted
    Dynamically typed
    Object Oriented & Functional
    GC
    Easy
    Sunday, October 21, 12

    View Slide

  26. class Presentation
    attr_accessor :name, :topic
    def initialize(name, topic)
    self.name = name
    self.topic = topic
    end
    def start
    puts "Hi, my name is #{name} \
    and I will talk about #{topic}."
    end
    end
    talk = Presentation.new("Matt", "Ruby")
    talk.start
    Sunday, October 21, 12

    View Slide

  27. Ruby
    Use case:
    Full Stack Web App
    Sunday, October 21, 12

    View Slide

  28. class Post < ActiveRecord::Base
    attr_accessible :content, :name, :title
    validates :name, :presence => true
    validates :title, :presence => true,
    :length => { :minimum => 5 }
    end
    Sunday, October 21, 12

    View Slide

  29. class PostsController < ApplicationController
    def index
    @posts = Post.all
    respond_to do |format|
    format.html # FYI, render index.html.erb
    format.json { render :json => @posts }
    end
    end
    end
    Sunday, October 21, 12

    View Slide

  30. Ruby
    Philosophy
    Sunday, October 21, 12

    View Slide

  31. Ruby
    what I dislike
    Often abused
    Overly complex specs
    Hard to follow/debug
    Not designed for parallelism
    Can’t be easily optimized
    Design choices that are hard to
    revert
    Sunday, October 21, 12

    View Slide

  32. Ruby
    what I like
    Expressive
    Malleable
    Human oriented
    Business efficient
    Everything is an object
    Functional language
    Great “go to” language
    Influenced other languages
    Great for DSL
    Sunday, October 21, 12

    View Slide

  33. Ruby
    how to get
    started
    http://tryruby.org
    http://ruby.railstutorial.org
    http://railsforzombies.org
    Sunday, October 21, 12

    View Slide

  34. JavaScript
    Sunday, October 21, 12

    View Slide

  35. interpreted
    dynamically typed
    object oriented* & functional
    GC
    easy
    Sunday, October 21, 12

    View Slide

  36. var Presentation = function(name, topic) {
    this.name = name;
    this.topic = topic;
    };
    Presentation.prototype.start = function(){
    return "Hi, my name is " + this.name +
    " and I will talk about " + this.topic + "."
    };
    var talk = new Presentation('Matt', 'JS');
    talk.start();
    Sunday, October 21, 12

    View Slide

  37. Use case:
    DOM manipulation
    Sunday, October 21, 12

    View Slide

  38. $(document).ready(function() {
    $("#orderedlist").find("li").each(function(i) {
    $(this).addClass("important");
    });
    });
    Sunday, October 21, 12

    View Slide

  39. Philosophy
    Sunday, October 21, 12

    View Slide

  40. what I dislike
    Scoping
    “Older” style syntax
    Limited concurrency
    “messy”
    Sunday, October 21, 12

    View Slide

  41. what I like
    Omnipresent
    High level
    Simple
    Functional
    Sunday, October 21, 12

    View Slide

  42. CoffeeScript
    Sunday, October 21, 12

    View Slide

  43. compiled/interpreted
    dynamically typed
    object oriented & functional
    GC
    easy
    Sunday, October 21, 12

    View Slide

  44. class Presentation
    constructor: (@name, @topic) ->
    start: () ->
    return "Hi, my name is " + this.name +
    " and I will talk about " + this.topic + "."
    talk = new Presentation("Matt", "CoffeeScript")
    talk.start()
    Sunday, October 21, 12

    View Slide

  45. Use case:
    DOM manipulation
    Sunday, October 21, 12

    View Slide

  46. $(document).ready ->
    $("a").hover =>
    @parents("p").addClass("highlight")
    Sunday, October 21, 12

    View Slide

  47. Philosophy
    Sunday, October 21, 12

    View Slide

  48. what I dislike
    debugging
    space delimited
    o_O effect
    too many ways to do a simple thing
    compilation phase
    still requires to know JS
    not for everyone
    Sunday, October 21, 12

    View Slide

  49. what I like
    Nicer syntax
    Tries to fix the scoping issues
    Easier to read (sometimes)
    More expressive
    Sunday, October 21, 12

    View Slide

  50. how to get
    started
    http://coffeescript.org/
    http://bit.ly/coffeeconsole
    Sunday, October 21, 12

    View Slide

  51. Objective-C
    Sunday, October 21, 12

    View Slide

  52. compiled
    dyn/static/weakly typed
    object oriented & “functional”*
    GC/ARC
    nightmare
    Sunday, October 21, 12

    View Slide

  53. #import
    @interface Presentation : NSObject
    @property (strong, nonatomic) NSString *name;
    @property (strong, nonatomic) NSString *topic;
    - (Presentation*) initWithNameAndTopic:(NSString*)name
    topic:(NSString*)topic;
    - (NSString*) start;
    @end
    presentation.h
    Sunday, October 21, 12

    View Slide

  54. #import "Presentation.h"
    @implementation Presentation
    - (Presentation*)initWithNameAndTopic:(NSString *)name
    topic:(NSString *)topic
    {
    self = [super init];
    if (self) {
    self.name = name;
    self.topic = topic;
    }
    return self;
    }
    - (NSString*)start{
    return [NSString stringWithFormat:@"This is %@, \
    and I will talk about %@.",
    self.name, self.topic];
    }
    @end
    presentation.m
    Sunday, October 21, 12

    View Slide

  55. #import "Presentation.h"
    Presentation *talk = [[Presentation alloc]
    initWithNameAndTopic:@"Matt"
    topic:@"Objective-C"];
    [talk start];
    example.m
    Sunday, October 21, 12

    View Slide

  56. Use case:
    iOS Application
    Sunday, October 21, 12

    View Slide

  57. Philosophy
    Sunday, October 21, 12

    View Slide

  58. what I dislike
    Header/Implementation
    Feels very 80s (with a new carpet)
    Annoying syntax
    Apple centric
    Sunday, October 21, 12

    View Slide

  59. what I like
    Object Oriented C
    Weakly typed
    New literals
    Blocks
    Good tooling
    Performant
    Designed with Cocoa in mind
    Cocoa
    Sunday, October 21, 12

    View Slide

  60. how to get
    started
    https://developer.apple.com/
    http://bit.ly/ios-programming
    http://bit.ly/objc-programming
    Sunday, October 21, 12

    View Slide

  61. Go
    Sunday, October 21, 12

    View Slide

  62. compiled
    structural/static typing
    object oriented*
    functional
    GC
    normal
    Sunday, October 21, 12

    View Slide

  63. package demo
    import "fmt"
    type Presentation struct {
    " Name, Topic string
    }
    func (p *Presentation) start() string {
    " return "This is " + p.Name +
    ", and I will talk about " + p.Topic + "."
    }
    func main() {
    " talk := &Presentation{Name: "Matt", Topic: "Go"}
    " fmt.Println(talk.start())
    }
    Sunday, October 21, 12

    View Slide

  64. Use case:
    concurrency
    Sunday, October 21, 12

    View Slide

  65. package main
    import (
    " "fmt"
    " "net/http"
    " "time"
    )
    var urls = []string{
    " "http://pulsoconf.co/",
    " "http://golang.org/",
    " "http://matt.aimonetti.net/",
    }
    type HttpResponse struct {
    " url string
    " response *http.Response
    " err error
    }
    Sunday, October 21, 12

    View Slide

  66. func asyncHttpGets(urls []string) []*HttpResponse {
    " ch := make(chan *HttpResponse, len(urls)) // buffered
    " responses := []*HttpResponse{}
    " for _, url := range urls {
    " " go func(url string) {
    " " " fmt.Printf("Fetching %s \n", url)
    " " " resp, err := http.Get(url)
    " " " ch <- &HttpResponse{url, resp, err}
    " " }(url)
    " }
    " for {
    " " select {
    " " case r := <-ch:
    " " " fmt.Printf("%s was fetched\n", r.url)
    " " " responses = append(responses, r)
    " " " if len(responses) == len(urls) {
    " " " " return responses
    " " " }
    " " default:
    " " " fmt.Printf(".")
    " " " time.Sleep(5e7)
    " " }
    " }
    " return responses
    }
    Sunday, October 21, 12

    View Slide

  67. func main() {
    " results := asyncHttpGets(urls)
    " for _, result := range results {
    " " fmt.Printf("%s status: %s\n", result.url,
    result.response.Status)
    " }
    }
    Sunday, October 21, 12

    View Slide

  68. $ go build concurrency_example.go && ./a.out
    .Fetching http://pulsoconf.co/
    Fetching http://golang.org/
    Fetching http://matt.aimonetti.net/
    .....http://golang.org/ was fetched
    .......http://pulsoconf.co/ was fetched
    .http://matt.aimonetti.net/ was fetched
    http://golang.org/ status: 200 OK
    http://pulsoconf.co/ status: 200 OK
    http://matt.aimonetti.net/ status: 200 OK
    Sunday, October 21, 12

    View Slide

  69. Philosophy
    Sunday, October 21, 12

    View Slide

  70. what I dislike
    A bit too low level for some
    Not so great GC
    Limited adoption
    Odd conventions at times
    Sunday, October 21, 12

    View Slide

  71. what I like
    simple specs
    modern std libs
    concurrency (goroutines/channels)
    sensible conventions
    fast compilation
    flexible code organization
    simpler take on OO
    features of FP
    error handling
    documentation
    source as documentation
    Sunday, October 21, 12

    View Slide

  72. how to get
    started
    http://tour.golang.org
    Sunday, October 21, 12

    View Slide

  73. Clojure
    Sunday, October 21, 12

    View Slide

  74. compiled
    dynamically typed (w/ hints)
    “object oriented*”
    functional
    GC
    nightmare
    Sunday, October 21, 12

    View Slide

  75. (defprotocol Talk "A conference talk"
    (start [p] "return the speaker and topic."))
    (defrecord Presentation [name topic]
    Talk; implement the Talk protocol
    (start [_] (str "Hi, this is " name
    " and I will talk about "
    topic ".")))
    (def talk (Presentation. "Matt" "Clojure"))
    (start talk)
    Sunday, October 21, 12

    View Slide

  76. Use case:
    Data Processing
    Sunday, October 21, 12

    View Slide

  77. (ns example.word-count
    (:use clojure.contrib.io
    clojure.contrib.seq-utils))
    (defn parse-line [line]
    (let [tokens (.split (.toLowerCase line) " ")]
    (map #(vector % 1) tokens)))
    (defn combine [mapped]
    (->> (apply concat mapped)
    (group-by first)
    (map (fn [[k v]]
    {k (map second v)}))
    (apply merge-with conj)))
    (defn sum [[k v]]
    {k (apply + v)})
    (defn reduce-parsed-lines [collected-values]
    (apply merge (map sum collected-values)))
    (defn word-frequency [filename]
    (->> (read-lines filename)
    (map parse-line)
    (combine)
    (reduce-parsed-lines)))
    Sunday, October 21, 12

    View Slide

  78. Philosophy
    Sunday, October 21, 12

    View Slide

  79. what I dislike
    not so simple
    not always consistent
    need to know a lot of functions/macros
    not really web focused
    brain stack overflow
    hard mental context switch
    meaningless error stacks
    Sunday, October 21, 12

    View Slide

  80. what I like
    really great for data processing
    isolate problems efficiently
    fast
    java interop
    Sunday, October 21, 12

    View Slide

  81. how to get
    started
    https://github.com/functional-koans/clojure-koans
    Sunday, October 21, 12

    View Slide

  82. Sunday, October 21, 12

    View Slide

  83. compiled
    static/inferred/dyn typed
    object oriented & functional
    GC
    normal/nightmare
    Sunday, October 21, 12

    View Slide

  84. class Presentation(val name: String,
    val topic: String) {
    val start = "My name is "+ name +
    " and I will talk about " +
    topic +"."
    }
    val talk = new Presentation("Matt", "Scala")
    talk.start
    Sunday, October 21, 12

    View Slide

  85. Use case:
    Service Oriented Architecture
    Sunday, October 21, 12

    View Slide

  86. Twitter’s Finagle
    Sunday, October 21, 12

    View Slide

  87. Sunday, October 21, 12

    View Slide

  88. Future + pipeline
    Sunday, October 21, 12

    View Slide

  89. val authenticatedUser: Future[User] =
    User.authenticate(email, password)
    val lookupTweets: Future[Seq[Tweet]] =
    authenticatedUser flatMap { user =>
    Tweet.findAllByUser(user)
    }
    Sunday, October 21, 12

    View Slide

  90. for {
    user <- User.authenticate(email, password)
    tweets <- Tweet.findAllByUser(user)
    } yield tweets
    Sunday, October 21, 12

    View Slide

  91. Futures also exist in Java,
    Akka/Scala 2.10,
    scalaz,
    lift...
    Sunday, October 21, 12

    View Slide

  92. Finagle: async, blocking or not futures that
    are composable
    Sunday, October 21, 12

    View Slide

  93. val service = new Service[HttpRequest, HttpResponse] {
    def apply(request: HttpRequest) =
    Future(new DefaultHttpResponse(HTTP_1_1, OK))
    }
    val address = new InetSocketAddress(10000)
    val server: Server[HttpRequest, HttpResponse] = ServerBuilder()
    .name("MyWebServer")
    .codec(Http())
    .bindTo(address)
    .build(service)
    Sunday, October 21, 12

    View Slide

  94. Philosophy
    Sunday, October 21, 12

    View Slide

  95. what I dislike
    huge surface
    stiff learning curve
    abused o_O syntax
    poor documentation
    feels like it’s trying to do everything
    JVM
    Sunday, October 21, 12

    View Slide

  96. what I like
    Close to Ruby/Python
    Easy to get started
    Inferred types
    Flexible functional approach
    Modern concerns (parallelism)
    Pattern matching
    Relatively rich ecosystem
    JVM/CLR
    Sunday, October 21, 12

    View Slide

  97. where to get
    started
    Twitter’s Scala school
    A Tour of scala
    Coursera’s online class
    Sunday, October 21, 12

    View Slide

  98. conclusion
    Sunday, October 21, 12

    View Slide

  99. sub
    title
    conf - Matt Aimonetti - @merbist
    “zend”
    developer
    Sunday, October 21, 12

    View Slide

  100. “java”
    developer
    Sunday, October 21, 12

    View Slide

  101. developer
    Sunday, October 21, 12

    View Slide

  102. problem
    solver
    Sunday, October 21, 12

    View Slide

  103. product
    builder
    Sunday, October 21, 12

    View Slide


  104. is just a
    detail
    Sunday, October 21, 12

    View Slide

  105. but choose
    wisely
    Sunday, October 21, 12

    View Slide

  106. languages
    shape
    how you
    solve problems
    Sunday, October 21, 12

    View Slide

  107. be
    curious
    learn
    a new language
    Sunday, October 21, 12

    View Slide

  108. Sunday, October 21, 12

    View Slide