Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Human Languages studied by linguists Sunday, October 21, 12

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Sunday, October 21, 12

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Interpreted vs Compiled Sunday, October 21, 12

Slide 10

Slide 10 text

Dynamically vs Statically Typed Sunday, October 21, 12

Slide 11

Slide 11 text

Object Oriented vs not OO Sunday, October 21, 12

Slide 12

Slide 12 text

Functional Programming vs not FP Sunday, October 21, 12

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Hello World Sunday, October 21, 12

Slide 15

Slide 15 text

Syntax Sunday, October 21, 12

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Sunday, October 21, 12

Slide 19

Slide 19 text

Pick your interest Sunday, October 21, 12

Slide 20

Slide 20 text

Sunday, October 21, 12

Slide 21

Slide 21 text

Sunday, October 21, 12

Slide 22

Slide 22 text

Sunday, October 21, 12

Slide 23

Slide 23 text

Sunday, October 21, 12

Slide 24

Slide 24 text

Ruby Sunday, October 21, 12

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

Ruby Philosophy Sunday, October 21, 12

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

JavaScript Sunday, October 21, 12

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Use case: DOM manipulation Sunday, October 21, 12

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

Philosophy Sunday, October 21, 12

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

CoffeeScript Sunday, October 21, 12

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

Use case: DOM manipulation Sunday, October 21, 12

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

Philosophy Sunday, October 21, 12

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

Objective-C Sunday, October 21, 12

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

#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

Slide 54

Slide 54 text

#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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

Use case: iOS Application Sunday, October 21, 12

Slide 57

Slide 57 text

Philosophy Sunday, October 21, 12

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

Go Sunday, October 21, 12

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

Use case: concurrency Sunday, October 21, 12

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

$ 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

Slide 69

Slide 69 text

Philosophy Sunday, October 21, 12

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

Clojure Sunday, October 21, 12

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

(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

Slide 76

Slide 76 text

Use case: Data Processing Sunday, October 21, 12

Slide 77

Slide 77 text

(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

Slide 78

Slide 78 text

Philosophy Sunday, October 21, 12

Slide 79

Slide 79 text

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

Slide 80

Slide 80 text

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

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

Sunday, October 21, 12

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

Twitter’s Finagle Sunday, October 21, 12

Slide 87

Slide 87 text

Sunday, October 21, 12

Slide 88

Slide 88 text

Future + pipeline Sunday, October 21, 12

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

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

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

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

Slide 94

Slide 94 text

Philosophy Sunday, October 21, 12

Slide 95

Slide 95 text

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

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

conclusion Sunday, October 21, 12

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

“java” developer Sunday, October 21, 12

Slide 101

Slide 101 text

developer Sunday, October 21, 12

Slide 102

Slide 102 text

problem solver Sunday, October 21, 12

Slide 103

Slide 103 text

product builder Sunday, October 21, 12

Slide 104

Slide 104 text

is just a detail Sunday, October 21, 12

Slide 105

Slide 105 text

but choose wisely Sunday, October 21, 12

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

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

Slide 108

Slide 108 text

Sunday, October 21, 12