Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@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 -
@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
-
@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? -
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. -
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? -
@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.
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
undefined