DEV Community

Discussion on: I've never become overly convinced that switch statements are that much cleaner than `if else if else if else if else`

Collapse
 
nicpolhamus profile image
Nicolas Polhamus

When I'm adding some new functionality to something the main thing I'm concerned with us maintainability, and a big part of that is code readability. If statements are easier to document, at least in my opinion, and they do a better job at being representative of their purpose and the current context of the code.
Switch blocks can certainly be contextual and representative, but it takes more effort to ensure that the context and logic are properly represented. I will say, that fallthrough can be very useful in the right scenarios.