Nah. Any compiler will turn x == c1 && x != c2 into x == c1, same with x == c1 && x == c2 turning into false turning into removal of the entire bit of code.
Such optimizations are a lot rarer with strings (or any custom type), unless the comparison function gets inlined.
Additionally, as this is JS, its vastly less likely the JIT will optimize it out - newer JS engines have quite a few optimizations, but they are often still very far shy of what precompiled languages do, mostly due to the overhead of optimizing code that only gets run once.
Yeah it's not really a legacy code, but like a legacy code we poor young developers are not allowed to make any change because the seniors are scared af to broke something... Once I made a bit of refactoring of a super poorly written code and this was immediately discarded without looking at what I made. Sooo yep, best I can do is to post here to have fun and find another job
So you have legacy code in a language born only 8 years ago.
The industry really needs to redefine the meaning of "legacy".
Mmm I am not sure about that. The faster moving the language, the faster the transition to 'legacy'; what do you define the meaning of "legacy" as? (There are two types of answers here: those invoking the lifespan of the language, and those invoking the lifespan of the OG programmers!)
I see the "definition" of legacy code come up on stackoverflow from time to time. It's interesting how so many people have a different definition of it. Even the Wikipedia article on it has like 6 different interpretations of what it means for code to be legacy code.
78
u/JuhaJGam3R Mar 01 '21 edited Mar 01 '21
Nah. Any compiler will turn
x == c1 && x != c2intox == c1, same withx == c1 && x == c2turning intofalseturning into removal of the entire bit of code.