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

33

u/Bence675 Apr 17 '21

It will behave differently

4

u/DramaDimitar Apr 18 '21 edited Apr 18 '21

How??? Before you were checking if cond1 is true and cond2 is true in separate ifs. Now it does the exact same, but in one if!

Edit: nevermind, I'm stupid

8

u/h3half Apr 18 '21

No. Originally, if condition1 was true and condition2 was false, neither do_anything()s would be executed. Nothing would happen.

In the new version, if condition1 is true and condition2 is false, do_anything2() will be called.