MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/msv49l/when_your_teammate_refactor_your_code/guwr335/?context=3
r/badcode • u/Bence675 • Apr 17 '21
216 comments sorted by
View all comments
772
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. 28 u/clemesislife Apr 17 '21 I think both ways have their up- /downsides. The solution of u/dyingpie1 is more confusing than the original code, but the original code can cause exactly what happened to OPs teammate, overseeing the condition1 && !condition2 case. 26 u/mfb- Apr 18 '21 I think the simple if elseif structure is less confusing than the nested option.
255
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.
28 u/clemesislife Apr 17 '21 I think both ways have their up- /downsides. The solution of u/dyingpie1 is more confusing than the original code, but the original code can cause exactly what happened to OPs teammate, overseeing the condition1 && !condition2 case. 26 u/mfb- Apr 18 '21 I think the simple if elseif structure is less confusing than the nested option.
28
I think both ways have their up- /downsides. The solution of u/dyingpie1 is more confusing than the original code, but the original code can cause exactly what happened to OPs teammate, overseeing the condition1 && !condition2 case.
condition1 && !condition2
26 u/mfb- Apr 18 '21 I think the simple if elseif structure is less confusing than the nested option.
26
I think the simple if elseif structure is less confusing than the nested option.
772
u/dyingpie1 Apr 17 '21
I would rewrite it as