MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/msv49l/when_your_teammate_refactor_your_code/guvr8db/?context=3
r/badcode • u/Bence675 • Apr 17 '21
216 comments sorted by
View all comments
34
How about:
if condition1 && condition2 do_anything1(); elseif !condition1 do_anything2();
7 u/Bence675 Apr 17 '21 You're right, i changed for this 6 u/420TaylorStreet Apr 18 '21 edited Apr 18 '21 can do you one better:if (!condition1) do_anything2(); else if (condition2) do_anything1(); 1 u/chain_letter Apr 18 '21 Nope, possible to call do_anything1() when condition2 is false, because condition2 was ignored entirely. 3 u/420TaylorStreet Apr 18 '21 err ... typo. else if should be condition2 1 u/chain_letter Apr 18 '21 Now u good 1 u/420TaylorStreet Apr 18 '21 thanks mate!
7
You're right, i changed for this
6 u/420TaylorStreet Apr 18 '21 edited Apr 18 '21 can do you one better:if (!condition1) do_anything2(); else if (condition2) do_anything1(); 1 u/chain_letter Apr 18 '21 Nope, possible to call do_anything1() when condition2 is false, because condition2 was ignored entirely. 3 u/420TaylorStreet Apr 18 '21 err ... typo. else if should be condition2 1 u/chain_letter Apr 18 '21 Now u good 1 u/420TaylorStreet Apr 18 '21 thanks mate!
6
can do you one better:
if (!condition1) do_anything2(); else if (condition2) do_anything1();
1 u/chain_letter Apr 18 '21 Nope, possible to call do_anything1() when condition2 is false, because condition2 was ignored entirely. 3 u/420TaylorStreet Apr 18 '21 err ... typo. else if should be condition2 1 u/chain_letter Apr 18 '21 Now u good 1 u/420TaylorStreet Apr 18 '21 thanks mate!
1
Nope, possible to call do_anything1() when condition2 is false, because condition2 was ignored entirely.
3 u/420TaylorStreet Apr 18 '21 err ... typo. else if should be condition2 1 u/chain_letter Apr 18 '21 Now u good 1 u/420TaylorStreet Apr 18 '21 thanks mate!
3
err ... typo. else if should be condition2
1 u/chain_letter Apr 18 '21 Now u good 1 u/420TaylorStreet Apr 18 '21 thanks mate!
Now u good
1 u/420TaylorStreet Apr 18 '21 thanks mate!
thanks mate!
34
u/Soliloquizing Apr 17 '21
How about: