Hacker News new | ask | show | jobs
by asattarmd 731 days ago
I'd remove the else if blocks since we're returning.

    private String generateGuessSentence(char candidate, int count) {
      if (count === 0) return "There are no " + candidate + "s";
      if (count === 1) return "There is 1 " + candidate;

      return "There are " + count + " " + candidate + "s";
    }
1 comments

I feel like single-line conditionals are harder to read in bigger projects. I remove the brackets in single-statement conditionals and loops, but I still use another line.
Braces _always_.

It just needs one tired / inexperienced / somethingelse coder to "quickly add" an extra call to the topmost if and then you'll have interesting issues.

I'll take the "ugly" braces every day compared to having risky structures like that in the code at all.

Thorough testing should catch all those "interestig" issues.

But easier maintainability I also favor braces everywhere.