Should switch statements always contain a default clause?

In one of my first code reviews (a while back), I was told that it’s good practice to include a default clause in all switch statements. I recently remembered this advice but can’t remember what the justification was. It sounds fairly odd to me now.

  1. Is there a sensible reason for always including a default statement?

  2. Is this language dependent? I don’t remember what language I was using at the time – maybe this applies to some languages and not to others?

21 Answers
21

Leave a Comment