0
+= 0.1
require   ‘yarv’
require   ‘syntax-1.9’
require   ‘stdlib-1.9’
require   ‘unicode’



   Stephen Touset <stephen@to...
Play Along at Home
$ svn export 
  http://svn.ruby-lang.org/repos/ruby/tags/v1_9_9_0 
  ruby-1.9.0

$   cd ruby-1.9.0
$   ...
YARV FTW

• Faster
• Less Memory
• Native threads*
• Fun Acronym
                    *concurrency of one
ruby 1.8   ruby 1.9   improvement
   app_answer      0.460      0.146        68%
       app_erb     1.655      1.646      ...
≈38% faster
  (62% as slow)
    ((twice-ish as fast))
Yet Another Meaningless Benchmark




       (http://www.timestretch.com/FractalBenchmark.html)
The Image Below is
Not Photoshopped
...thus ending the
language wars once and
          for all
Shiny New Syntax
• Lambda shortcut
• Implicit #call
• Literal hashes
• Block parameters
• Function parameter insanity
• Bl...
lambda, v1.9


   ->
λ
_
/|
_
    /|
->
λ
->
 “I found lambda!”
            - Matz
c = lambda {|a, b| [b, a] }


        - becomes -

c = ->(a, b) { [b, a] }
Implicit #call
c = lambda {|a, b| [b, a] }
c.call(1, 2)

        - becomes -

c = ->(a, b) { [b, a] }
c.(1,2)
Block Parameters
lambda {|a, b, c = 1, &d| d.call }
                ^
syntax error, unexpected '}' ...

           - becom...
laaaaame
lambda { yield }.call { puts ‘hi’ }
LocalJumpError: no block given

            - becomes -

-> { yield }.() { pu...
Literal Hashes
{ :a => 1, :b => 2,
  :c => 3, :d => 4 }

    - becomes -

{ a: 1, b: 2,
  c: 3, d: 4 }
W...T...
def foo(a, b = 100, c)
  puts “#{a} #{b} #{c}”
end

foo(3)       # => ArgumentError
foo(3, 5)    # => 3, 100, 5
f...
...F

def bar(a, b = nil, *c, d)
end
Block Local Variables

   i = Elephant.new
   [1,2,3].map {|i| i * 2 }

   i # => #<Elephant:0x3688b4>
stdlib.succ!
• send no longer calls private methods
• #methods and its siblings return symbols
• class variables are not i...
#tap that class
Passes an object to a block, then returns the object
              (useful for call chaining)




‘foo’.ta...
Wait, did I see that
    correctly?

  tap(&:upcase!)
      ^^
Enumerator Love

[1, 2, 3].cycle {|i| puts i }        # loops forever puts-ing 1,2,3

[1, 2, 3].first(2)                  ...
Ordered Hashes

h = { a: 1, b: 2, c: 3 }

h        # => { a: 1, b: 2, c: 3 }
h.keys   # => [ :a, :b, :c ]
h.values # => [ ...
Encoded Strings

• No longer Enumerable
 • String#bytes
 • String#lines
 • String#each_char
• “One-char-wide” String behavior
#!/usr/bin/ruby -w
     # -*- coding: utf-8 -*-

      open(filename, ‘r:utf-8’)


encodings = %w{ utf-8        utf-16
   ...
More Info

•   Summary of Changes in 1.9
     http://eigenclass.org/hiki/Changes+in+Ruby+1.9


•   Mechanically Verified 1....
exit(0)
Upcoming SlideShare
Loading in...5
×

Ruby 1.9

2,680

Published on

The Ruby 1.9 presentation I gave before the ATL RUG.

Published in: Technology, Education
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,680
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
92
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "Ruby 1.9"

  1. 1. += 0.1 require ‘yarv’ require ‘syntax-1.9’ require ‘stdlib-1.9’ require ‘unicode’ Stephen Touset <stephen@touset.org>
  2. 2. Play Along at Home $ svn export http://svn.ruby-lang.org/repos/ruby/tags/v1_9_9_0 ruby-1.9.0 $ cd ruby-1.9.0 $ ./configure --program-suffix 1.9 $ make $ make test $ chmod a+x bin/irb $ PATH=. RUBYLIB=quot;./libquot; bin/irb
  3. 3. YARV FTW • Faster • Less Memory • Native threads* • Fun Acronym *concurrency of one
  4. 4. ruby 1.8 ruby 1.9 improvement app_answer 0.460 0.146 68% app_erb 1.655 1.646 0.5% app_factorial 0.762 0.858 -13% app_fib 5.572 1.530 73% app_mandelbrot 2.034 0.848 58% app_pentomino 92.811 50.778 45% app_raise 1.984 2.474 -25% app_strcat 1.414 1.113 21% app_tak 8.306 2.083 75% app_tarai 6.530 1.660 75% app_uri 3.555 2.027 43%
  5. 5. ≈38% faster (62% as slow) ((twice-ish as fast))
  6. 6. Yet Another Meaningless Benchmark (http://www.timestretch.com/FractalBenchmark.html)
  7. 7. The Image Below is Not Photoshopped
  8. 8. ...thus ending the language wars once and for all
  9. 9. Shiny New Syntax • Lambda shortcut • Implicit #call • Literal hashes • Block parameters • Function parameter insanity • Block local variables
  10. 10. lambda, v1.9 ->
  11. 11. λ
  12. 12. _ /|
  13. 13. _ /|
  14. 14. ->
  15. 15. λ -> “I found lambda!” - Matz
  16. 16. c = lambda {|a, b| [b, a] } - becomes - c = ->(a, b) { [b, a] }
  17. 17. Implicit #call c = lambda {|a, b| [b, a] } c.call(1, 2) - becomes - c = ->(a, b) { [b, a] } c.(1,2)
  18. 18. Block Parameters lambda {|a, b, c = 1, &d| d.call } ^ syntax error, unexpected '}' ... - becomes - ->(a, b, c = 1, &d) { d.call }
  19. 19. laaaaame lambda { yield }.call { puts ‘hi’ } LocalJumpError: no block given - becomes - -> { yield }.() { puts ‘hi’ } LocalJumpError: no block given
  20. 20. Literal Hashes { :a => 1, :b => 2, :c => 3, :d => 4 } - becomes - { a: 1, b: 2, c: 3, d: 4 }
  21. 21. W...T... def foo(a, b = 100, c) puts “#{a} #{b} #{c}” end foo(3) # => ArgumentError foo(3, 5) # => 3, 100, 5 foo(3, 4, 5) # => 3, 4, 5
  22. 22. ...F def bar(a, b = nil, *c, d) end
  23. 23. Block Local Variables i = Elephant.new [1,2,3].map {|i| i * 2 } i # => #<Elephant:0x3688b4>
  24. 24. stdlib.succ! • send no longer calls private methods • #methods and its siblings return symbols • class variables are not inherited, now work like class instance variables (thus obsoleting my entire metaprogramming presentation) • blocks passable to #[] • enumerator love • Oniguruma regexp engine
  25. 25. #tap that class Passes an object to a block, then returns the object (useful for call chaining) ‘foo’.tap(&:upcase!).tap {|s| s.gsub! /oo/, ‘u’ }
  26. 26. Wait, did I see that correctly? tap(&:upcase!) ^^
  27. 27. Enumerator Love [1, 2, 3].cycle {|i| puts i } # loops forever puts-ing 1,2,3 [1, 2, 3].first(2) # => [1,2] [1, 2, 3].map.with_index {|o,i| i} # => [0, 1, 2] [1, 3, 4, 2].take {|i| i < 4 } # => [1, 3] [1, 2, 3].reduce(:+1) # => 6
  28. 28. Ordered Hashes h = { a: 1, b: 2, c: 3 } h # => { a: 1, b: 2, c: 3 } h.keys # => [ :a, :b, :c ] h.values # => [ 1, 2, 3 ]
  29. 29. Encoded Strings • No longer Enumerable • String#bytes • String#lines • String#each_char • “One-char-wide” String behavior
  30. 30. #!/usr/bin/ruby -w # -*- coding: utf-8 -*- open(filename, ‘r:utf-8’) encodings = %w{ utf-8 utf-16 ascii-8bit euc-jp }
  31. 31. More Info • Summary of Changes in 1.9 http://eigenclass.org/hiki/Changes+in+Ruby+1.9 • Mechanically Verified 1.9 Changelog http://eigenclass.org/hiki/mechanically-verified-ruby19-changelog • Matz’ RubyConf 2007 Keynote http://rubyconf2007.confreaks.com/d2t1p8_keynote.html
  32. 32. exit(0)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×