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.

4

u/[deleted] Apr 17 '21

the if not variation seems more readable to me. it's always interesting to me to see what people think is more clear.

1

u/MightyMeepleMaster Apr 18 '21

Fully agree. Readability is always subjective. Some of us prefer few and compact lines others more elaborate sequences.

Either way there is one thing which is really annoying: Technology prima donnas who use obfuscated code to demonstrate that they are the best leet haxx0rs in the hood.

2

u/[deleted] Apr 21 '21

Heh this is my single line FizzBuzz I did to make fun of those:

print(*[(("" if (i % 3) else "Fizz") + ("" if (i % 5) else "Buzz") or i) for i in range(1, count + 1)], sep = "\n")