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()

-4

u/Bojangly7 Apr 18 '21

There's no reason to play code golf.

Sacrificing readability for lines is never a good idea.

3

u/dyingpie1 Apr 18 '21

It’s not just for a few lines. It’s so mistakes like this don’t happen. It’s important to fully understand the flow of the program. The way I wrote it is more explicit and is less likely to cause others to make this mistake. But also, it depends on the context, such as whether condition1 and/or condition2 are edge cases and whether the negation of condition1 makes sense.

0

u/Bojangly7 Apr 18 '21

No. There is no edit needed.

3

u/dyingpie1 Apr 18 '21

Good response.

-4

u/Bojangly7 Apr 18 '21

You're just wrong there's not much more to it.

4

u/dyingpie1 Apr 18 '21

Very fitting that you had a CMV post be removed for being unwilling to change your opinion.

-1

u/Bojangly7 Apr 18 '21

I haven't posted on cmv for like probably a year did you really go all the wya through my profile because you're wrong about this?

I'm a career software engineer. If one of my team made this change I'd reject the pull request

3

u/dyingpie1 Apr 18 '21 edited Apr 18 '21

You’re cmv post was from 28 days ago.

And I am a software engineer too.

As you can see, I’m not the only one who agrees with me.

Don’t be so stubborn you are unwilling to accept that there may be reasons to do something like this.

You must be frustrating to work with.

0

u/Bojangly7 Apr 18 '21

You're making a change that doesn't need to be made. The original code is perfectly readable.

You're not only wasting time and resources to make a useless change you're wasting time arguing for it.

You can't admit that you're wrong and learn. You're insisting your right and your ego is driving you to bad decisions.

I would fire you.

If you really are a software engineer I hope yo God you aren't like this at work. Otherwise you will never learn if you are so ego driven.

→ More replies (0)