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

Make Up Your Own "Hello, World!"

Make Up Your Own "Hello, World!"

We all love Ruby. Maybe we’ve only been paid to write code in Ruby (and maybe JavaScript). But there are so many other languages out there, and they all have strengths, weaknesses, and very different communities surrounding them.
Let’s talk about language exploration. We’ll discuss how to learn a new language, considerations when introducing things to production, and come up with some ideas for Ruby and it’s ecosystem. Plan on dipping your toes in Elixir, Go, Haskell, Rust, and Scala during the session.

Justin Campbell

March 10, 2015
Tweet

More Decks by Justin Campbell

Other Decks in Programming

Transcript

  1. Learn (verb) 4 gain or acquire knowledge of or skill

    in (something) by study, experience, or being taught 4 commit to memory 4 become aware of (something) by information or from observation
  2. TDD

  3. TDD

  4. 4 Billboard 4 Blog 4 Chat 4 Counter 4 Dice

    4 Stats 4 Storage 4 Twitter 4 URL Shortener
  5. # Ruby post '/' do token = shortener.shorten(params[:url]) [201, "/#{token}"]

    end get '/:token' do |token| full_url = shortener.expand(token) halt 404 unless full_url redirect full_url end
  6. # Ruby class Shortener def shorten(url) token = id_generator.next.to_s urls[token]

    = url token end def expand(token) urls[token] end end
  7. ; Clojure (def token (atom 0)) (defn next-token [] (swap!

    token inc)) (next-token) ; => 1 (next-token) ; => 2
  8. # Ruby def shorten(url) token = id_generator.next.to_s urls[token] = url

    token end {- Haskell -} shorten :: Url -> Token
  9. # Ruby def shorten(url) token = id_generator.next.to_s urls[token] = url

    token end {- Haskell -} shorten :: Url -> Token {- shorten is a function from a Url to a Token -}
  10. # Ruby def shorten(url) token = id_generator.next.to_s urls[token] = url

    token end {- Haskell -} type Token = String type Url = String shorten :: Url -> Token
  11. # Ruby def shorten(url) token = id_generator.next.to_s urls[token] = url

    token end {- Haskell -} type Token = String type Url = String shorten :: Url -> Token shorten url = token where {- increment token, store url -}
  12. {- Haskell -} type Token = String type Url =

    String shorten :: Url -> Token
  13. {- Haskell -} type Token = String type Url =

    String shorten :: Url -> World -> Token
  14. {- Haskell -} type Token = String type Url =

    String shorten :: Url -> World -> World
  15. {- Haskell -} type Token = String type Url =

    String data World = World { id :: Int, urls :: Map Token Url } shorten :: Url -> World -> World
  16. {- Haskell -} type Token = String type Url =

    String data World = World { id :: Int, urls :: Map Token Url } shorten :: Url -> World -> World shorten url world = newWorld where nextId = succ $ _id world token = show nextId newUrls = insert token url $ _urls world newWorld = World nextId newUrls
  17. {- Haskell -} type Token = String type Url =

    String data World = World { id :: Int, urls :: Map Token Url } shorten :: Url -> World -> World
  18. {- Haskell -} type Token = String type Url =

    String data World = World { id :: Int, urls :: Map Token Url } shorten :: Url -> World -> World expand :: Token -> World -> Maybe Url
  19. Nim

  20. # Nim type Token = string type Url = string

    var id = 0 var urls = newTable[Token, Url]() proc shorten*(url: Url): Token = id += 1 let token = intToStr(id) urls[token] = url return token proc expand*(token: Token): Url = if hasKey(urls, token): return urls[token]
  21. {- Haskell -} expand :: Token -> World -> Maybe

    Url # Nim proc expand*(token: Token): Url = # ...
  22. # Nim proc expand*(token: Token): Url = # ... shorten("google.com")

    # => "1" expand("1") # => "google.com" expand("54321") # => nil
  23. nil

  24. Go

  25. // Go url, err := shortener.expand(token); if err != nil

    { http.NotFound(response, request); } http.Redirect(response, request, url, 301);
  26. // Go url, err := shortener.expand(token); // if err !=

    nil { // http.NotFound(response, request); // } http.Redirect(response, request, url, 301);
  27. // Go url, err := shortener.expand(token); // if err !=

    nil { // http.NotFound(response, request); // } http.Redirect(response, request, url, 301); // ???
  28. In two weeks, Im headed to India to give a

    keynote at a Go Conference. Last year this time, I was like, "why do I need a GOROOT and GOPATH?" - Bryan Lyles
  29. # Ruby get '/:token' do |token| begin url = shortener.expand(token)

    redirect url rescue # ??? halt 404 end end
  30. # Elixir {:ok, url} = Shortener.Core.expand(conn.params[:token]) # ** (MatchError) no

    match of right hand side value: # {:error, "Token not found"}
  31. # Ruby def halve(number) number / 2.0 end halve 5

    # => 2.5 halve "5" # strings don't respond to `/`
  32. " Clojure Plug 'guns/vim-clojure-static' Plug 'guns/vim-sexp' Plug 'tpope/vim-classpath' Plug 'tpope/vim-fireplace'

    Plug 'tpope/vim-leiningen' Plug 'tpope/vim-sexp-mappings-for-regular-people' " CoffeeScript Plug 'kchmck/vim-coffee-script' " Elixir Plug 'elixir-lang/vim-elixir' " Go Plug 'fatih/vim-go' " Haskell Plug 'dag/vim2hs' Plug 'eagletmt/ghcmod-vim' Plug 'shougo/vimproc.vim' " JavaScript Plug 'pangloss/vim-javascript' " Nim Plug 'zah/nimrod.vim'
  33. " OCaml Plug 'ocamlpro/ocp-indent' Plug 'the-lambda-church/merlin' " PureScript Plug 'raichoo/purescript-vim'

    " Ruby Plug 'ecomba/vim-ruby-refactoring' Plug 'hwartig/vim-seeing-is-believing' Plug 'jgdavey/vim-blockle' Plug 'tpope/vim-rails' Plug 'tpope/vim-rake' Plug 'vim-ruby/vim-ruby' " Rust Plug 'wting/rust.vim' " Scala Plug 'derekwyatt/vim-scala' " Shell Plug 'markcornick/vim-bats' Plug 'rosstimson/bats.vim' " Thrift Plug 'solarnz/thrift.vim'
  34. make default: deps test deps: which bundle || gem install

    bundler bundle check || bundle install test: bundle exec rspec spec/
  35. "If you do what you've always done, you'll get what

    you've always gotten" - Henry Ford
  36. The principle of linguistic relativity holds that the structure of

    a language affects the ways in which its respective speakers conceptualize their world, i.e. their world view, or otherwise influences their cognitive processes. http://en.wikipedia.org/wiki/Linguistic_relativity
  37. Hiring Filters: Write your app in Rails, and enter the

    hiring fracas. Or, use Haskell or Clojure and hire better people with less competition. — Ben Orenstein twitter.com/r00k/status/563821546016636928
  38. # Ruby describe User do subject(:user) { described_class.new(first_name, last_name) }

    let(:first_name) { "Justin" } let(:last_name) { "Campbell" } it "concatenates a full name" do expect(user.full_name).to start_with(first_name) expect(user.full_name).to end_with(last_name) end end
  39. # Ruby describe User do def test_full_name user = User.new("Justin",

    "Campbell") assert_equal "Justin Campbell", user.full_name end end
  40. $ sbt test [info] Set current project ... [info] Run

    completed in 397 milliseconds. [info] Total number of tests run: 1 [info] Suites: completed 1, aborted 0 [info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0 [info] All tests passed. [success] Total time: 2 s
  41. $ sbt ~test [info] Set current project ... [info] Run

    completed in 397 milliseconds. [info] Total number of tests run: 1 [info] Suites: completed 1, aborted 0 [info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0 [info] All tests passed. [success] Total time: 2 s 1. Waiting for source changes... (press enter to interrupt)
  42. $ lein test Retrieving lein-exec/lein-exec/0.3.1/lein-exec-0.3.1.pom from clojars Retrieving lein-exec/lein-exec/0.3.1/lein-exec-0.3.1.jar from

    clojars Retrieving org/clojure/clojure/1.6.0/clojure-1.6.0.pom from central Retrieving org/sonatype/oss/oss-parent/7/oss-parent-7.pom from central Retrieving org/clojure/tools.nrepl/0.2.3/tools.nrepl-0.2.3.pom from central [...] lein test ... Ran 1 tests containing 1 assertions. 0 failures, 0 errors.
  43. $ bundle exec rspec Could not find rspec-5.0.0 in any

    of the sources Run `bundle install` to install missing gems.
  44. $ bundle exec rspec The following gems are missing *

    rspec (3.0.0) Installing rspec 3.0.0 Bundle complete! ............... Finished in 0.16548 seconds 15 examples, 0 failures
  45. # Ruby class Animal def initialize(type) @type = type end

    end Animal.new(:cat) # => #<Animal @type=:cat>
  46. # Ruby require 'newk/everything' class Animal def initialize(type) @type =

    type end end Animal(:cat) # => #<Animal @type=:cat>
  47. Go

  48. Dude, sucking at something is the first step towards being

    sorta good at something - Jake, Adventure Time