Friday, December 5, 2008

it's the little things...

sigh. I found myself making a modification to a legacy Java app the other day and I wanted to use a switch instead of this convoluted if/elseif/else mess that was in the code. I drew a blank... WHY couldn't I remember how to do ranges in a Java switch statement?!

Something like Ruby has... (and this is simplified considerably)

tempF = 60
result = case score
when 0..32: "Frozen"
when 33..40: "Way too cold for me"
when 41..55: "Too cold for me"
when 56..82: "Brrrr..."
when 83..110 "Now we're talking"
else "Time to move"
end
puts result
Oh, that's right... Java doesn't DO ranges (gotta love it's C++ roots)

No comments: