DEV Community

loading...

Discussion on: Basics of switch cases and defaults

Collapse
lifelongthinker profile image
Sebastian

The BIG problem with switch/case/if/then/else (especially among newly devs) is that they can invite you to write really bad code and design.

This is especially the case when these are used repetitively and thus encode a lot of invariance. Usually, such structures could (and should) be replaced by polymorphism, list structures, functional approaches and/or other means.

Collapse
jennakoslowski profile image
JennaKoslowski Author

I've definitely noticed myself leaning on those when I know there are other ways to do what I need to do (especially working with arrays) so I've been trying not to lean on them as much. I think it's because it's clearer logic but I'm definitely going to go look at what you listed!