r/badcode • u/ivanrgazquez • Oct 24 '20
python Worst thing, this variable is never used.
4
u/sekex Oct 24 '20
It could make sense if it was trying to implement some sort of trait and if turn was not a boolean
2
u/ivanrgazquez Oct 24 '20
But in that case why change_turn()
1
u/sekex Oct 25 '20
Sometimes you have to implement traits or abstract classes so you create a function that does nothing
1
u/RFC793 Oct 25 '20
return not bool(turn)0
Oct 25 '20
[deleted]
1
u/RFC793 Oct 25 '20
The bool constructor accepts any type.
0
Oct 25 '20
[deleted]
2
u/RFC793 Oct 25 '20 edited Oct 25 '20
But it is the exact same truth value testing as the original code. There’s a set of Falsey values built into the language (False, None, zeroes, empties). For custom classes it relies on
__nonzero__or__len__, otherwise it is True.3
239
u/Encursed1 Oct 24 '20
It doesn't even change turn...
143
u/WhyYouLetRomneyWin Oct 24 '20
Ahh, thats why we use turn = change_turn()
59
39
8
3
1
19
u/asgaines25 Oct 24 '20
Hopefully not for a self driving car...
2
u/JeffSergeant Oct 27 '20 edited Oct 27 '20
If not (not change_turn()) then: dont_turn(not change_turn(), false) else turn = not change_turn()
69
u/h_dani1337 Oct 24 '20
Just use an exclamation mark oh my god
112
u/BlazingThunder30 Oct 24 '20
It's Python so would be
not turn25
19
u/IAmAnIssue Oct 24 '20
no no clearly we need the solution that assumes too much:
turn^=19
u/RecDep Oct 25 '20
def nand(a, b):
return not (a and b) turn = nand(turn, turn)1
u/AutoModerator Oct 25 '20
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
/u/RecDep, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
You can find some examples in the reddit help documentation.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
0
7
2
7
37
u/oxetyl Oct 24 '20
Is turn a global 🤢
7
u/OnlySeesLastSentence Oct 25 '20
It better.
2
u/PixxlMan Oct 27 '20 edited Feb 26 '21
No, it's supplied by editing process memory at runtime. A breakpoint is put before it.
7
u/mnkisala Oct 24 '20
Is this the way the ternary if operator works in python? Im not a python programmer, and I can't really understand this syntax.
13
u/Terrain2 Oct 24 '20
it’s just plain english, “do this if something, else do that”,
False if turn else Trueis equivalent in many other languages toturn ? false : true, or in other words, it’s inverting a boolean, otherwisenot turnor in other languages the more compact!turn
2
2
1
u/incrediblejonas Oct 25 '20
the way you framed this makes it look like one of those motivational quotes haha
1
1
-2
76
u/RidleyGrayMusic wicked Oct 24 '20
Me to whoever wrote this monstrosity: Who are you, who are so dumb in the ways of science