2008

2007

Ruby: Pipes and strange variables? Why, oh why?!

▁ nov 29 2007

I briefly looked at Ruby a while ago, when it started getting attention because of Rails and all that. This week I decided to take a closer look at it, and skimmed through some tutorials. Ruby seems nice, but there are some things that make me wonder wtf is going on…

First of all, take this code example from Chris Pine’s tutorial:

languages = ['English', 'German', 'Ruby']
languages.each do |lang|
end

Looks nice and all, except… Pipes? For the love of Jeebus, why?! The language seems consistent and well designed, until someone thought it was a good idea to throw some pipes into the mix. Why?! This is mind-bogglingly unintuitive. The language is beautiful and free of unnecessary characters, but then suddenly the mysterious pipes appear. I searched around a little without finding any answers, and also asked a Ruby-guy, but he was clueless. If anyone could explain to me why it makes sense to have pipes here, please do.

Second, in Ruby in Twenty Minutes, this little gem pops up:

if __FILE__ == $0

Seriously, $0? Perl tried that and failed. Thus, using the module English is now considered best practice, and will enable you to use $PROGRAM_NAME instead of the mysterious variable $0. Ruby should have learned from Perls mistake, and it is a mystery why it hasn’t.

That’s it for me for now, I’ll let you know if I find other annoyances. ;)

← Previous: Web Application Gotchas: Modifying data with links (GET requests)  //  Next: Pointless Fibonacci Benchmark #4253: Python vs. Simula

comments

foo, 1 year ago:

smalltalk used pipes for “temporary variables.” (not that it justifies the ugly.) http://en.wikipedia.org/wiki/Smalltalk#Variable_declarations

powered by