Timeline for Switch case for one condition
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 17, 2017 at 22:44 | comment | added | gnasher729 | The OP didn't get confused. He wanted to know whether a switch should be replaced with an if (another question is whether you should ask for it in a code review). He fully understood the code. "Wondering why it is written that way" is not being confused. | |
Mar 17, 2017 at 22:05 | comment | added | chris | @gnasher729, The question you're answering exists because someone got confused by a single case switch statement. For every line of code you write, someone reading it will always wonder why it was written that way. | |
Mar 17, 2017 at 20:33 | comment | added | gnasher729 | How would anyone be confused by a single case switch statement? And why on earth would I write code that I know I need to change soon, which is extra work and extra chances of introducing a bug? | |
Mar 17, 2017 at 10:05 | comment | added | kmaczuga | "There are situations where today I have one case, but I know I'm going to add more cases tomorrow" - In those situations I'd still prefer to use the if statement and change it to switch statement only after adding more cases. If by some reason you change your mind, and there won't be more cases added, there is a chance that the single case switch statement will remain in the code and will confuse someone in the future. | |
Mar 16, 2017 at 21:00 | history | answered | gnasher729 | CC BY-SA 3.0 |