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

Nikita: The Ruby Secret Agent

brixen
January 29, 2012

Nikita: The Ruby Secret Agent

Talk presented at RubyConf 2011.

brixen

January 29, 2012
Tweet

More Decks by brixen

Other Decks in Technology

Transcript

  1. Nikita
    THE RUBY SECRET AGENT
    Brian Ford / @brixen

    View full-size slide

  2. http://www.dailyyonder.com/thin-forests-swell-rural-economy/2009/01/19/1844

    View full-size slide

  3. "Ruby has the
    best tools"
    -- No One Ever

    View full-size slide

  4. http://www.lifeoptimizer.org/2008/07/23/being-happy-secrets-of-happy-people/
    Ruby is a
    beautiful
    language

    View full-size slide

  5. http://www.lifeoptimizer.org/2008/07/23/being-happy-secrets-of-happy-people/
    Ruby
    makes
    me happy

    View full-size slide

  6. http://ableveterans.com/able-vets-climb-mt-rainier
    Rails is a terrific framework

    View full-size slide

  7. Ruby is
    srs bsns
    !_!

    View full-size slide

  8. Billions of dollars

    View full-size slide

  9. Who here is paid
    to write Ruby?

    View full-size slide

  10. People are
    leaving Ruby

    View full-size slide

  11. Node.js
    Clojure
    Scala

    View full-size slide

  12. polyglot is the
    new liberal

    View full-size slide

  13. All the candidates
    are equally qualified,
    but you should
    choose me

    View full-size slide

  14. http://icouldntdecide.blogspot.com/

    View full-size slide

  15. http://picasaweb.google.com/lh/photo/bayTKUSuvLPJ8em1oMPbUg
    This was
    fun...

    View full-size slide

  16. http://picasaweb.google.com/lh/photo/bayTKUSuvLPJ8em1oMPbUg
    ...but itʼs
    sooo slow

    View full-size slide

  17. Business is hard

    View full-size slide

  18. Business is
    customers

    View full-size slide

  19. Business decisions
    balance
    fear and greed

    View full-size slide

  20. Developers are
    not paid
    to be happy

    View full-size slide

  21. They are paid
    to make
    customers happy

    View full-size slide

  22. If developer
    happiness and
    customer
    happiness collide...

    View full-size slide

  23. "Twitter: From
    Ruby on Rails
    to the JVM"
    http://vimeo.com/29993216
    Stop Watch Now

    View full-size slide

  24. Critical Ruby Issues
    Garbage collection
    Concurrency
    Performance
    Tools

    View full-size slide

  25. U worried
    bro?
    http://www.isiticim.com/2010/05/he-was-worried.html

    View full-size slide

  26. Smalltalk
    was an
    awesome
    language
    http://www.isiticim.com/2010/05/he-was-worried.html

    View full-size slide

  27. am I going to have to use Java again?
    http://forums.steves-digicams.com/people-photos/150189-sad-little-boy-advice-re-post-production-required.html#b

    View full-size slide

  28. If tools are
    the answer,
    what are
    the questions?

    View full-size slide

  29. How do I
    understand
    this code?

    View full-size slide

  30. Fear of the
    unknown

    View full-size slide

  31. Solutions & Problems
    Optional Typing
    Hidden Typing
    Refinements
    -w

    View full-size slide

  32. Optional Typing

    View full-size slide

  33. Ruby is about
    behavior

    View full-size slide

  34. You are what you do

    View full-size slide

  35. Classes
    organize code

    View full-size slide

  36. Classes
    support
    encapsulation

    View full-size slide

  37. Three pillars of OO
    Encapsulation
    Polymorphism
    Inheritance

    View full-size slide

  38. Inheritance:
    relationships
    between
    behaviors

    View full-size slide

  39. Hidden Typing
    Typing requirements that are
    concealed from Ruby code

    View full-size slide

  40. Undefined
    or
    Not documented

    View full-size slide

  41. Ruby cannot
    participate

    View full-size slide

  42. VALUE
    rb_to_float(VALUE val)
    {
    if (TYPE(val) == T_FLOAT) return val;
    if (!rb_obj_is_kind_of(val, rb_cNumeric)) {
    rb_raise(rb_eTypeError, "can't convert %s into Float",
    NIL_P(val) ? "nil" :
    val == Qtrue ? "true" :
    val == Qfalse ? "false" :
    rb_obj_classname(val));
    }
    return rb_convert_type(val, T_FLOAT, "Float", "to_f");
    }

    View full-size slide

  43. def wrong(a, b)
    unless a.kind_of? Numeric
    raise "must be an instance of Numeric"
    end
    # ...
    end

    View full-size slide

  44. Ruby is dictating
    the structure of
    programs

    View full-size slide

  45. brittle
    unnecessary
    wrong

    View full-size slide

  46. Types tell you
    what you cannot do

    View full-size slide

  47. Like all walls,
    people try to
    defeat them

    View full-size slide

  48. Refinements

    View full-size slide

  49. One of the leading
    proposals...

    View full-size slide

  50. ... for ruining Ruby

    View full-size slide

  51. Primary purpose
    hide incompatible changes

    View full-size slide

  52. naming - powerful
    abstraction for
    handling
    complexity

    View full-size slide

  53. libraries - still need
    integration testing

    View full-size slide

  54. applications - does
    not help program
    comprehension

    View full-size slide

  55. “What if?”
    programming

    View full-size slide

  56. horizontal
    vs
    vertical
    integration

    View full-size slide

  57. Hidden
    in the parser

    View full-size slide

  58. Not Ruby objects

    View full-size slide

  59. No
    programmatic
    control

    View full-size slide

  60. Not configurable

    View full-size slide

  61. No real
    semantic analysis

    View full-size slide

  62. Critical Ruby Issues
    Garbage collection
    Concurrency
    Performance
    Tools

    View full-size slide

  63. Ruby is
    bringing a knife
    to a gunfight

    View full-size slide

  64. Rubinius Foundations
    Garbage Collection
    Concurrency
    Just-in-time Compiler
    Tools

    View full-size slide

  65. Rubinius Status Update
    Concurrent threads
    1.9 features
    Windows
    JIT improvements

    View full-size slide

  66. Generational

    View full-size slide

  67. Copying
    Compaction
    the garbage is never seen

    View full-size slide

  68. Fully concurrent
    Ruby threads

    View full-size slide

  69. concurrent
    vs
    parallel

    View full-size slide

  70. hipster Actors
    since before they were cool

    View full-size slide

  71. Just-in-time
    FAAAAST

    View full-size slide

  72. Rubinius
    implements
    Ruby
    differently

    View full-size slide

  73. Rubinius uses
    Ruby

    View full-size slide

  74. Consistent system

    View full-size slide

  75. Trees & Leaves

    View full-size slide

  76. How does
    Rubinius
    use Ruby?

    View full-size slide

  77. icon - symbol

    View full-size slide

  78. $ rbx
    irb(main):001:0> ast = "a = 1".to_ast
    => #@value=#@line=1> @line=1 @name=:a @variable=nil>
    irb(main):002:0> ast.class
    => Rubinius::AST::LocalVariableAssignment

    View full-size slide

  79. $ irb(main):003:0> ast.ascii_graph
    LocalVariableAssignment
    @line: 1
    @name: :a
    @variable: nil
    @value: \
    FixnumLiteral
    @value: 1
    @line: 1
    => [["@value", #@value=1 @line=1>]]

    View full-size slide

  80. $ irb(main):004:0> ast.to_sexp
    => [:lasgn, :a, [:lit, 1]]

    View full-size slide

  81. $ irb(main):005:0> "a = 1".to_sexp
    => [:lasgn, :a, [:lit, 1]]

    View full-size slide

  82. What is Ruby?

    View full-size slide

  83. Everything is an
    object

    View full-size slide

  84. class A
    a = 1
    end
    module M
    b = 2
    end

    View full-size slide

  85. def m(a)
    a + b
    end
    m { |x| x * 1 }

    View full-size slide

  86. # ruby_script.rb
    puts "hello"

    View full-size slide

  87. $ rbx
    irb(main):001:0> def m(a, b)
    irb(main):002:1> a + b
    irb(main):003:1> end
    => #

    View full-size slide

  88. $ rbx compile -e 'puts 1' -B
    ============= :__script__ ==============
    Arguments: 0 required, 0 post, 0 total
    Arity: 0
    Locals: 0
    Stack size: 2
    Lines to IP: 1: 0..8
    0000: push_self
    0001: meta_push_1
    0002: allow_private
    0003: send_stack :puts, 1
    0006: pop
    0007: push_true
    0008: ret
    ----------------------------------------

    View full-size slide

  89. $ rbx compile -e 'class A; def m; end; end' -B -N __script__
    ============= :__script__ ==============
    Arguments: 0 required, 0 post, 0 total
    Arity: 0
    Locals: 0
    Stack size: 6
    Lines to IP: 1: 0..28
    0000: push_rubinius
    0001: push_literal :A
    0003: push_nil
    0004: push_scope
    0005: send_stack :open_class, 3
    0008: dup_top
    0009: push_rubinius
    0010: swap_stack
    0011: push_literal :__class_init__
    0013: swap_stack
    0014: push_literal #
    0016: swap_stack
    0017: push_scope
    0018: swap_stack
    0019: send_stack :attach_method, 4
    0022: pop
    0023: send_stack :__class_init__, 0
    0026: pop
    0027: push_true
    0028: ret
    ----------------------------------------

    View full-size slide

  90. $ rbx compile -e 'class A; def m; end; end' -B -N A
    ================== :A ==================
    Arguments: 0 required, 0 post, 0 total
    Arity: 0
    Locals: 0
    Stack size: 5
    Lines to IP: 1: 2..15
    0000: push_self
    0001: add_scope
    0002: push_rubinius
    0003: push_literal :m
    0005: push_literal #
    0007: push_scope
    0008: push_variables
    0009: send_stack :method_visibility, 0
    0012: send_stack :add_defn_method, 4
    0015: ret
    ----------------------------------------

    View full-size slide

  91. Everything is a
    CompiledMethod

    View full-size slide

  92. Rubinius uses Ruby
    to build a
    consistent system

    View full-size slide

  93. "Ruby has the
    best tools"
    -- No One Ever

    View full-size slide

  94. my idea of a tool

    View full-size slide

  95. I want you to
    write tools

    View full-size slide

  96. Architecture
    Client/Server
    Separate GUI
    Data as binding
    Modular gems

    View full-size slide

  97. CompiledMethod
    database

    View full-size slide

  98. Class browser

    View full-size slide

  99. Coverage
    and
    profiling

    View full-size slide

  100. Bytecode
    instrumentation

    View full-size slide

  101. $ rbx
    irb(main):001:0> class F
    irb(main):002:1> dynamic_method :m do |g|
    irb(main):003:2* g.push :self
    irb(main):004:2> g.push_literal g.name
    irb(main):005:2> g.send :p, 1, true
    irb(main):006:2> g.ret
    irb(main):007:2> end
    irb(main):008:1> end
    => #
    irb(main):009:0> F.new.m
    :m
    => nil

    View full-size slide

  102. AST
    transformation

    View full-size slide

  103. Documentation

    View full-size slide

  104. Analysis
    variables used before set
    unused variables
    misnamed methods
    code quality

    View full-size slide

  105. Custom tools

    View full-size slide

  106. Ruby is at a
    critical point

    View full-size slide

  107. I did not change
    Ruby

    View full-size slide

  108. Available in
    1.8 and 1.9

    View full-size slide

  109. Respect business
    that bet on Ruby

    View full-size slide

  110. http://forums.steves-digicams.com/people-photos/150189-sad-little-boy-advice-re-post-production-required.html#b

    View full-size slide

  111. I don’t
    want to be
    this kid.
    Do you?

    View full-size slide

  112. Help Ruby
    help you

    View full-size slide

  113. github.com/rubinius/rubinius

    View full-size slide

  114. github.com/brixen/nikita

    View full-size slide