Consider the following two snippets, with braces:
switch (var) {
case FOO: {
x = x + 1;
break;
}
case BAR: {
y = y + 1;
break;
}
}
<
You say the braces can be omitted because no variables names are being reused. By reusing variable names, I assume you mean declaring a new variable of the same type.
The braces are actually most useful to ensure you don't end up reusing the same variable in different case
s by mistake. They don't declare any variables today, but someone will add them tomorrow and without the braces the code is error-prone.
With braces.
There are so many things that can go wrong with switch statements I try to avoid them where I can, i.e.
Using braces is one way to prevent both intentional and accidental sharing of variables between case statements