3 ms·
Wait. People put `if` in the same category as `goto`? I understand the problems with `goto`, but I'd never heard a case against `if` before.
by Wowfunhappy 4y ago
Wait. People put `if` in the same category as `goto`?
I understand the problems with `goto`, but I'd never heard a case against `if` before.
- naikrovek 4y agothere are lots of "experts" who will tell you that the branch for either outcome of an if can only be executed after the if condition is evaluated, and that therefore "ifs are slow; don't use if". I had a colleague once that would turn all his "if" statements into "switch" clauses because "no branches means it is so much faster" and people listened to him closely.
- rep_lodsb 4y agoHow could anyone believe that switch would work without evaluating its argument or branching?
- naikrovek 4y agoif you believe the person saying it is an "expert", that's how. "i-am-an-expert" syndrome often seen in 24-yo "senior" developers with sizeable egos.
- 8n4vidtmkvmk 4y agoi avoid some ifs for perf.. but only when i can write something equivalent with like 1 line and certainly not a switch
- moffkalast 4y agoCan't say about how impactful it is on a CPU, but if you're using them on a GPU you can run into serious issues of stalling out other cores with significant branching, since the same code runs for multiple data units at the same time and if all don't finish at the same time the rest in the batch will just sit around and wait until it's all done.