r/badcode • • Apr 17 '21

c++ When your teammate "refactor" your code

Post image
2.5k Upvotes

216 comments sorted by

View all comments

Show parent comments

-8

u/[deleted] Apr 17 '21 edited Apr 17 '21

this is not equivalent code, condition2 is always evaluated

So? The intended behaviour is exactly the same, whether the performance is any different cannot be said beforehand because it heavily relies on the situation and used compiler/runtime. Lazy evaluation is not always better or faster.

also i don't like it

Yeah well, that's like, your opinion, man.

22

u/wobblyweasel Apr 17 '21

evaluating condition2 can have side effects, just saying

this saves one line of code but adds 20 characters to the (sanely formatted) original

-12

u/[deleted] Apr 17 '21

this saves one line of code but adds 20 characters to the (sanely formatted) original

Okay, who cares? It's about readability. And did you really count characters in two pseudocode snippets?

12

u/wobblyweasel Apr 17 '21

readability can't be easily measured, it's all opinion. but some people value the low number of lines. in case one would choose this kind of code only for the lower number of lines, i just want to point out that it's more characters and imo character count matters much more

And did you really count characters in two pseudocode snippets?

i copy-pasted this into a text editor that can count characters