re: I've never become overly convinced that switch statements are that much cleaner than `if else if else if else if else` VIEW POST

TOP OF THREAD FULL DISCUSSION
re: I could easily see if I'm dealing with a returnable statement over 20 lines where the return value is based on multiple conditionals or is impossib...

I broadly agree with the idea that functions should be small, but care should be taken not to break up logically sequential operations that really belong together just to comply with this principle.

More important to me is that a function should have one clearly defined purpose and not mash together a bunch of logically separate operations.

Switches tend to be used for doing multiple separate things based on some value. It is not always bad, but I always evaluate whether there is a better more extensible way to do it than a switch when I see it.

I'm not saying I've never used a switch, but it is generally not one I use unless there is a really good reason.

code of conduct - report abuse