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

Ruby: The Bad Parts

Ruby: The Bad Parts

Slides from my talk at RubyC 2015.

Bozhidar Batsov

May 31, 2015
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. Array#compact! static VALUE rb_ary_compact_bang(VALUE ary) { VALUE *p, *t, *end;

    long n; rb_ary_modify(ary); p = t = (VALUE *)RARRAY_CONST_PTR(ary); /* WB: no new reference */ end = p + RARRAY_LEN(ary); while (t < end) { if (NIL_P(*t)) t++; else *p++ = *t++; } n = p - RARRAY_CONST_PTR(ary); if (RARRAY_LEN(ary) == n) { return Qnil; } ary_resize_smaller(ary, n); return ary; } lame
  2. Array#compact! def compact! Rubinius.check_frozen if (deleted = @tuple.delete(@start, @total, nil))

    > 0 @total -= deleted reallocate_shrink() return self else return nil end end Rubinius
  3. Ruby 2.2 includes many new features and improvements for the

    increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.
  4. Ruby 2.2 includes many new features and improvements for the

    increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.
  5. Ruby 2.2 includes many new features and improvements for the

    increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.
  6. Ruby 2.2 includes many new features and improvements for the

    increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.
  7. Ruby 2.2 includes many new features and improvements for the

    increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.
  8. Ruby 2.2 includes many new features and improvements for the

    increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.
  9. –Matz “Under the current plan, I am not going to

    remove flip-flop from 2.0, since we are not going to made incompatible changes anytime soon. We have to wait until 3.0.” https://bugs.ruby-lang.org/issues/5400
  10. class SomeClass =begin This is a top comment. Or is

    it? =end def some_method end end
  11. class SomeClass =begin This is a top comment. Or is

    it? =end def some_method end end
  12. collect => map inject => reduce detect => find select

    => find_all sprintf => format length => size raise => fail
  13. pry(main)> A = 5 => 5 pry(main)> A = 6

    (pry):39: warning: already initialized constant A (pry):38: warning: previous definition of A was here => 6 pry(main)> Class = 3 (pry):40: warning: already initialized constant Class => 3 pry(main)> Class => 3
  14. class Parent @@class_var = 'parent' def self.print_class_var puts @@class_var end

    end class Child < Parent @@class_var = 'child' end Parent.print_class_var # => will print "child"
  15. [1] pry(main)> defined? 10 => "expression" [2] pry(main)> defined? Test

    => nil [3] pry(main)> defined? TrueClass => "constant"
  16. $:

  17. $;

  18. $*

  19. { :one => 1, :two => 2 } { :'one.1'

    => 1, :'two.2' => 2 } { 'one' => 1, 'two' => 2 } { 1 => 'one', 2 => 'two' }
  20. irb(main)> 'Bruce' =~ /B(.*)/ => 0 irb(main)> $~ => #<MatchData

    "Bruce" 1:"ruce"> irb(main)> $1 => "ruce" irb(main)> Regexp.last_match => #<MatchData "Bruce" 1:"ruce"> irb(main)> Regexp.last_match(0) => "Bruce" irb(main)> Regexp.last_match(1) => "ruce"
  21. irb(main)> 'Bruce'.match(/B(.*)/) => #<MatchData "Bruce" 1:"ruce"> irb(main)> 'Bruce'.match(/B(.*)/) do |m|

    irb(main)> puts m[0] irb(main)> puts m[1] irb(main)> end Bruce ruce => nil
  22. The Kill List • Net::* • DRb • REXML •

    RSS • Rinda • WEBrick • XML