4 ms·
else-if has useful properties, which allows designing flows with simpler condition statements and allows processor to jump less and lose less time (low-power sy
by bayindirh 2y ago
else-if has useful properties, which allows designing flows with simpler condition statements and allows processor to jump less and lose less time (low-power systems are still and will be a thing).
If we didn't have else-if, somebody will certainly lament "If we had something called else-if, I'd not have fixed a lot of bugs due this complex condition statements in various languages. The person who opposes implementation of such a simple construct should endure the Confy Chair".
So, it goes both ways.
- orwin 2y agoI'm not a branchless coding fanatic at all, but arguing for else-if with execution speed arguments isn't the way. Moreover, else-if is probably the most misused conditional, so while I disagree that it shouldn't exist (it has some uses), GP has a point. Although linters now are good enough now to catch poorly used conditionals, so his point is way less relevant than it was a decade ago.
- bayindirh 2y ago> but arguing for else-if with execution speed arguments isn't the way. Depends on the code base and problem domain you code / live in. In most cases you're right, but in my domain it's a different story. > Moreover, else-if is probably the most misused conditional You can misuse anything in any language, so by this logic we should argue that we shall abolish all programming altogether. I can misuse threads to make a program slower, misuse memory allocator to fragment the memory, etc. etc. So I don't think "but people misuse it" is a great argument either.