3 ms·
> Fast forward a few years Sounds like it was just what was needed at the time and worked better/longer than most abstractions.
by harrisonjackson 3y ago
> Fast forward a few years
Sounds like it was just what was needed at the time and worked better/longer than most abstractions.
- RandallBrown 3y ago> Sounds like it was just what was needed at the time The problem I've seen often in codebases is that as an abstraction or pattern grows more unwieldy, they don't take the time to update it. They often don't get revisited until they're so bad that they can't be ignored. Handling a something with a switch or if/else is fine if there's only 2 or 3 options, but people will often just keep piling on. When it's 10 things, changing it becomes much more work so people will continue to add to it. Then when it breaks at 20 things, someone will come in and say "Why did we write it this way in the first place? It doesn't make any sense!" I'm often torn between pragmatically writing the simplest code possible and being proactive about abstracting early to prevent an eventual breakdown of the pattern.
- edgyquant 3y agoWhy is a switch bad? Python uses a giant switch statement to run it’s opcodes
- Pannoniae 3y agoHow does a switch break at 20 items? Any respectable compiler or interpreter should handle that fine. If it was 32k cases, I could imagine why it would raise an error. But 20? Seriously? Often, writing more cases into a switch statement is way easier and less boiler-plate-y than abstracting it out to subclasses or a dictionary or whatever.