« Training on Cascading Style Sheets | Main | Setting your colour theme through PHP »

December 17, 2006

Ruby's case - no break

It has always struck me that switch statements in languages like C, PHP, Tcl and Java are very longwinded and clumsy, with a need for blocks and blocks, and every case having to end with a break (or equivalent) to stop multiple cases being run via a drop-through. I can understand why they were written that way in the first place but ... ouch.

Ruby's case / where, then, is a breath of fresh air. Easy block structure, multiple options allowed (and a special === test that helps make the case selection easy) and no need for those breaks either!

Larry Wall has steadfastly refused requests for a switch in Perl as you don't need it and ... he agrees with me ... it's clumsy. But Perl 6 will have a given alternative with when clauses which works in a similar way to the superb Ruby solution. My hat off to Matz and Larry.

Posted by gje at December 17, 2006 10:13 AM

Comments

Post a comment

! Comment registration is required but no TypeKey token has been given in weblog configuration!
Well House Consultants Ltd. Copyright 2008