One thing I love about Ruby (vs php)

The case (aka switch in other languages) control structure in Ruby is great. The first when clause that evaluates true is the only one executed.

Compare to PHP’s switch, which lets execution fall-through to every passing case until it finds a break. That’s just wrong. It’s so counter-intuitive. Sure, a veteran PHP programmer will have those breaks hardcoded into their fingertips, but that’s learned, not instinctual behavior. And yeah, you can get clever and take advantage of the cascading execution, but you do it at the expense of legibility. How many debugging hours have been spent chasing down forgotten breaks?

Ruby, on the other hand, does it right. The language doesn’t even give you the option of letting execution fall through. Less is more here. Less mental clutter and debugging, more natural, clean code.

31 January 2008 | ruby | Comments

Leave a Reply

  1.  
  2.  
  3.  

About Me

I work at outside.in during the day. On nights and weekends I do stuff and work on side projects, which you can read about here.
View my outside.in blogmap.

    Meta