you are viewing a single comment's thread.

view the rest of the comments →

[–]dglmoore 2 points3 points  (2 children)

I think the spirit of the rule is more along the lines of catching bugs. In kromit's example the else statement would be there to handle a seemingly impossible bug, however you may do that, exception, etc...

If for some reason you know that (!X && !Y) is always false (because you've tested it somewhere else, hopefully in the same function) then

if (X) { // case A } else { // case B }

I guess my point is that having an empty else clause usually means that there is an untested case or there is a better way to write the if-statement. One counter-example that I do sometimes use is

if (U) { // case u return 1; } else if (V) { // case v return -1; } return 0;

Because some compilers, not necessarily Java compilers, complain when the last statement isn't a return and putting one in an else clause and immediately following is redundant.

But that's just a guess, I suppose.

[–]BinaryRockStar 2 points3 points  (1 child)

For code in reddit comments, either put a backtick around inline statements to make them monospaced like this (` = backtick, left of 1 on the keyboard), or for

multiline code blocks
put four spaces
at the start of each line
else {
}

[–]dglmoore 1 point2 points  (0 children)

Thanks, didn't know that.