20

Developer 1: Stop changing all my loops into switches!

Developer 2: if you'd learn when to use a switch I wouldn't have to change it for you!

-My 2 devs argument today

#officechat #good2betheboss

Comments
  • 3
    you dont use switch. period.
  • 0
    @rookiemaverick care too elaborate? Although I (think I) know when to use a switch over an if-statement, I am curious about your statement.

    #alwayseagertolearn
  • 0
    @kanduvisla if u r going to check for five cases out of 200 then switch is the solution else for five out of five or fifty out of fifty for is the best way for latency
  • 0
    @rookiemaverick so what you're trying to say is that switch only makes sense if multiple cases require the same action?

    But what about semantic and readability?

    Also, I don't quite understand what you mean with "for". A for-loop?
  • 0
    for I =0; ptr !=null; I ++(
    __fnarr [I]
    }

    where __fnarr is
    static int __fnarr (args) =
    [case 1] = dosomefunc ();
    :
    :
    [casr n] = DOSONEFUNX ()

    I hope u got the idea here. there is good article on so. search for how to replace switch with for.
  • 0
    I see articles. Although I must say I'm more PHP/JavaScript, although I see examples on how to replace switch with an associative array.

    Now I can imagine that for low level languages these choices matter, but should I, who is writing in a high level language, now refactor all my code?
  • 0
    @kanduvisla it depends on you. sometimes such small things piled up and add to latency. or may be I am wrong about high level languages.
  • 1
    @rookiemaverick cool. thanks for the new insight in switch statements.
Add Comment