r/badcode • • Oct 24 '20

python Worst thing, this variable is never used.

Post image
1.2k Upvotes

50 comments sorted by

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

60

u/ivanrgazquez Oct 24 '20

That would be a Computer Science degree Professor.

-3

u/RidleyGrayMusic wicked Oct 25 '20

So you’re telling me, a 15 year old noob like me that doesn’t even know how to use GitHub knows more than a CS Degree Prof.?

3

u/Kippenvoer Oct 25 '20

Are you having troubles with Git or GitHub ? When i started with developing when i was 14 i learned about Gitkraken, a GUI, Git suddenly was easy

3

u/RidleyGrayMusic wicked Oct 25 '20

GitHub... I can get my head around Git more or less

2

u/mormispos Oct 26 '20

What’s confusing about GitHub?

3

u/Lysdal Oct 25 '20

computer science is not about programming

2

u/RidleyGrayMusic wicked Oct 25 '20

True, but you expect SOME level of programming knowledge from someone with a CS Degree

3

u/PixxlMan Oct 27 '20

This is one snippet of code. You can't just assume everything else is terrible.

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

u/[deleted] Oct 25 '20

[deleted]

1

u/RFC793 Oct 25 '20

The bool constructor accepts any type.

0

u/[deleted] 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

u/Toucandigit Oct 25 '20

You’d probably just do not bool(turn) then

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

u/HoratioMG Oct 24 '20

Oh we're doing that now are we...

39

u/npafitis Oct 25 '20

fUnCtionaL ProGRAmming

8

u/DaMastaCoda Oct 25 '20

UCL GRA

0

u/[deleted] Oct 25 '20

[deleted]

2

u/R3D3-1 Oct 25 '20

Mostly just bad function naming.

8

u/tias Oct 24 '20

You have a sick mind

3

u/nuephelkystikon Oct 25 '20

turn obviously is a descriptor and toggles on readout.

1

u/JeffSergeant Oct 27 '20

not_turn() would have been several orders of magnitude more painful.

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 turn

25

u/h_dani1337 Oct 24 '20

Indeed. I just tried out python 2 years ago so I forgot things.

19

u/IAmAnIssue Oct 24 '20

no no clearly we need the solution that assumes too much:

turn^=1

9

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

u/[deleted] Oct 25 '20

[deleted]

1

u/IAmAnIssue Oct 26 '20

now now why would we ever want that

2

u/jarfil Oct 24 '20 edited Dec 02 '23

CENSORED

7

u/CuntPot Oct 24 '20

“not turn”

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 True is equivalent in many other languages to turn ? false : true, or in other words, it’s inverting a boolean, otherwise not turn or in other languages the more compact !turn

2

u/ties113 Oct 24 '20

This gives me a headache

2

u/[deleted] Oct 25 '20

Tesla's self driving turn algorithm leaked.

1

u/incrediblejonas Oct 25 '20

the way you framed this makes it look like one of those motivational quotes haha

1

u/aderthedasher Oct 25 '20

Worst thing, you call that a variable

1

u/Cherylnip Feb 07 '21

Ok that is a change-turner

-2

u/[deleted] Oct 25 '20

Unpopular opinion: Visual Studio has the worst formatting all around