News for hackers. Stuff that matters.
Re:The Performance Impact of C++'s `final` Keyword by KerrAvon on Monday April 22, 2024 @07:56PM (#40126968)
> `if(x==1) elseif(x==2)...` because switch was "faster" and rejected my PR

Yeah, that's never been true. Old compilers would often compile a switch to __slower__ code because they'd tend to always go to a jump table implementation.

A better reason to use the switch is because it's better style in C-like languages. Using an if statement for that sort of thing looks like Python; it makes the code harder to maintain.

Re:The Performance Impact of C++'s `final` Keyword by wzdd on Tuesday April 23, 2024 @07:12AM (#40130520)
And it's better style because it better conveys intent. An if-else chain in C/C++ implies there's something important about the ordering of cases. Though I'd say that for a very small number of cases it's fine.

(Also, Python has a switch-like construct now.)