3 ms·
Without having seen this specific SO thread, I can easily imagine both 1. agreeing that the 7-line switch-based code is the better solution to a little SO-quest
by sanderjd 10y ago
Without having seen this specific SO thread, I can easily imagine both 1. agreeing that the 7-line switch-based code is the better solution to a little SO-question-sized problem, and 2. finding that same solution with no abstraction inflexible and "smelly" in a huge codebase very actively developed by tons of people. Context matters, and knowing what the context is currently and predicting what it will be in the future are some of the tough things about programming.
- hinkley 10y agoI used to have answers, now most of the time I say 'it depends'. Some days I wish I could take the blue pill and not have to try to explain the nuances of context. I think objectively the code is better for it but sometimes it takes more social sophistication than I possess. I end up spending too much time talking in post mortems and it all sounds like 'I told you so'
- BeetleB 10y agoThis. If it's a small program with limited scope, switches are fine. If it's part of a much larger program, there's a chance that switch will explode to switching on the same thing all over the codebase. However, I think GP's point is valid. If during a code review I have a switch and it makes no sense to abstract it, I'd smack the reviewer on the head if he/she wants me to "fix" it.