r/badcode • • Apr 17 '21

c++ When your teammate "refactor" your code

Post image
2.5k Upvotes

216 comments sorted by

View all comments

772

u/dyingpie1 Apr 17 '21

I would rewrite it as

If (!condition1) do_anything2()
Else if (condition2) do_anything1()

255

u/MightyMeepleMaster Apr 17 '21

The original code was fine because it was fairly easy to read. All other variants posted here are more compact but also more confusing.

Either way it doesn't matter. Any decent compiler will generate the same object code regardless of how you write it.

2

u/JuhaJGam3R Apr 17 '21

Either way it doesn't matter.

terrible mindset which seems to have been behind every single legacy project there is. clarity is important. the original was not only fine but pretty amazing.

4

u/MightyMeepleMaster Apr 18 '21

Either way it doesn't matter.

terrible mindset which seems to have been behind every single legacy project there is.

I thought I made it sufficiently clear that I meant "it doesn't matter in terms of execution efficiency" Readability and clarity is, in fact, of essential importance.