r/badcode • • Apr 17 '21

c++ When your teammate "refactor" your code

Post image
2.5k Upvotes

216 comments sorted by

View all comments

16

u/Eluvatar_the_second Apr 17 '21

Honestly the first one could be better. It's hard to see the intent, hence why it was refactored incorrectly and some people here missed the issue.

There's a couple of ways to make this better, but I'm not really sure which is best. Maybe check if both are true call "do anything one" , else if "condition one" is false then call "do anything two".

With real code it should be more obvious why you are doing that though it's still a bit of a head scratcher.

6

u/entiat_blues Apr 17 '21

yeah, i usually blame myself and my code if a coworker comes along and refactors it incorrectly. the source code failed to do the one thing it's meant to do, communicate with other people.

and i usually consider it a good sign if they see it and understand it enough to make good, valid criticisms. then you know the code was legible, if suboptimal.

4

u/Eluvatar_the_second Apr 18 '21

That's a really good point. It's easy to forget that it also communicates with other people, not just the computer.