No more fall through in case statement?

Jason House jason.james.house at gmail.com
Tue Jan 8 07:44:52 PST 2008


S. Wrote:
> Programming requires a brain.   
> 
> You should go read DailyWTF for awhile.  It is possible to do the most ridiculous things no matter how carefully the language is crafted.  We should just stay away from hand-holding and focus on making things easier.


You're right that we're capable of doing any and all kinds of stupid things.  I'm guilty of missing semicolons, break statements, and all kinds of other stuff.  Bugs pop up everywhere.  The easier they are for the compiler to spot and the simpler it is for a human to spot, the better.  Debugging is not just the job of the programmer who wrote code 5 minutes ago, but also the maintainer 6 months down the road.  I also like this quote from the pragmatic programmer: "It's not about if you'll remember, it's about when you'll forget"

I consider discussions on making switch statements safer a valid and important discussion...  One of my attractions to D is that it's willing to change stuff we hold near and dear in order to find a better way of doing things.

My personal take on all this switch stuff is:
  * Silently falling-through is dangerous
     (common switch error when coding, easy to miss in code review)
  * Silently not falling-through is dangerous (to C coders, etc)
  * A single case with commas is great, but won't be used by all
  * {} syntax may be a reasonable compromise
  * Explicitly requiring "break", "fall", or "assert(0)" at the end of a case may be the best solution.




More information about the Digitalmars-d mailing list