4 ms·
I'd remove the else if blocks since we're returning. private String generateGuessSentence(char candidate, int count) { if (count === 0) return "There
by asattarmd 2y 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";
}
- nj5rq 2y agoI 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.
- theshrike79 2y agoBraces _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.
- tredigi 2y agoThorough testing should catch all those "interestig" issues. But easier maintainability I also favor braces everywhere.