Why Ruby Scares Me

Ruby scares me. It’s not the language that strikes fear in my heart, however; it is the community.

The Reasons

  1. They treat Ruby as the Messiah — there is nothing better. There is nothing else. Only Ruby.
  2. Community Leader Idol Wordship — did anyone catch the (online presence) death of _why?
  3. “Now we can finally get things done”. — See next question.
  4. Have you ever seen Ruby code? Look at below.
  5. See Reason # 4.
1
2
3
4
5
6
7
8
def remember(&a_block)
  @block = a_block
end
 
remember {|name| puts "Hello, #{name}!"}
 
@block.call("Jon")
# => "Hello, Jon!"

Can you really tell me, with a degree of certainty, what that’s supposed to do?

Please, just shoot me now.

  • Amen... Although to be fair, there is some pretty decent looking Ruby code out there too.
  • still_rgz
    I have to agree with Steven, the example is ugly because it's contrived, a problem requiring such functionality would look intuitive.

    Although I agree that there's a lot of noise here. Example, it is not obvious from the example that you are editing the root Object, IANAR but doesn't this mean that every (new?) object now has a remember method and --potentially-- a @block attribute. It's definitively not intuitive that @block exists because it was binded to a globally implicit self object, the lambda expression is ugly but Python's is worse anyway. the block parameter syntax is fine, it's just a shame that it can't take multiple blocks like SmallTalk's. @block.call is stupid, no true functions or functors is sad.
  • Steven
    Your post is not constructive. My rebuttal isn't either:

    1. Kettle, meet Pot. Can't we all just agree PHP sucks?
    2. Vaguely. Maybe we can ask the Benevolent Dictator or Larry Wall for details.
    3-5. It's pretty straight forward. Since someone already pointed out you can do it in Python, here it is in perl:

    sub remember {
    $block = shift;
    }

    remember(sub {print "Hello, $_[0]!" });

    $block->("Jon");

    Here it is in Lua:

    function remember (a_block)
    block = a_block
    end

    remember(function (name) print(string.format("Hello, %s!", name)) end)

    block("Jon")

    And PHP:

    google, copy + paste
  • Daan
    I've never programmed in Ruby, but I guess this would be a somewhat accurate Python translation:

    import sys

    def remember(a_block):
    global block
    block = a_block

    remember(lambda name: sys.stdout.write("Hello %s!\n" % name))

    block("Jon")
    # => "Hello, Jon!"
  • The language itself strikes fear in my heart too after your example.

    Ruby: Fearsome!
blog comments powered by Disqus