Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    If you need a switch, this could be a sign that a code needs refactoring. When it comes to these two options, I think that first one is better. Commented Sep 28, 2016 at 8:05
  • 3
    Um, a switch is a perfectly good structure when used properly. It is very useful if you want to explicitly list out all possibilities, but also have groups of results with the same answers. A switch doesn't mean it needs refactoring. Commented Sep 28, 2016 at 8:44
  • 2
    @Nelson, my absolute pet hate in programming is sentences of the form "x is a perfectly good feature when used properly". I see folk apply it to singletons, goto, inheritance, mutability, switch etc etc etc. The problem is, in 99.999% of the time, it isn't used properly. So "don't use feature x" is actually excellent advice. It can then be safely ignored by the tiny group of folk who understand about edge cases where it is needed and only use it in those cases. And from experience those who says "x is a perfectly good feature when used properly" don't know when to use it properly. Commented Sep 28, 2016 at 9:03
  • 3
    Whether one should use a switch or not is a whole other debate. Lets keep it related. Commented Sep 28, 2016 at 9:16
  • Possible duplicate of Where did the notion of "one return only" come from? Commented Sep 28, 2016 at 10:05