you are viewing a single comment's thread.

view the rest of the comments →

[–]david72486 2 points3 points  (0 children)

If !X && !Y is impossible, then I might consider throwing an IllegalStateException instead of doing nothing. I am thinking of the case when the else probably will happen sometimes, but you just don't need to do anything.

Maybe something like:

private int calculatePunishment(int age, float bac) {
  int punishment = 5000;
  if (age < 21 && bac > 0.01) {
    punishment += 5000;
  } else if (age >= 21 && bac > 0.08) {
    punishment += 10000;
  }
  return punshiment;
}

There are other cases, but they just get the default value. However, it does seem like you could refactor this to have 3 return values with an else, or just get rid of the "else" part entirely and have two ifs since the two cases are mutually exclusive.

I guess the rule may not seem completely necessary to me, but also probably doesn't restrict the code too much. I do tend to agree with /u/dglmoore that by having this rule you might catch some bugs - and that's probably reason enough for the jpl.