Skip to content

One thing I love about Ruby (vs php)

by cory on January 31st, 2008
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.

From → ruby

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS