86

Just replaced a 300 line switch case with a simple if statement inside a foreach loop.
Feels sooo good man

Comments
  • 2
    Refactoring FTW!
  • 11
    Never saw 300 lines switch before o_o
  • 6
    Apparently 4 months ago I figured it could be a good idea lol
  • 2
    Holy fuck who writes 300 lines switch case :O
  • 3
    @ElCapitan yea I know I know XD
  • 4
    I've seen/written 300 lines Redux reducers, which are switch statements too. Nothing wrong usually
  • 1
    What language? You know C/C++ switch statements are actually an O(1) hash table data structure on the assembly level. Take a look at the assembly code generated
  • 1
    @rmahey you're right. Java does that too with an instruction called tableswitch if the case values are compact resulting in a constant lookup. If the case values are sparse, it switches to the instruction LookupSwitch which is O(log n)
  • 0
    Sounds like do-while loop would be better in this case.
Add Comment