r/badcode • u/mdgraph_us • Jul 01 '22
python due to some bad variable naming (I had a variable naked o) it took me half an hour to figure out why this was highlighted as unreachable
878
Upvotes
r/badcode • u/mdgraph_us • Jul 01 '22
231
u/InterstellarMat Jul 01 '22
Jesus wept
134
u/SouthernZhao Jul 01 '22
A naked variable? Naughty!
61
u/KimPeek Jul 01 '22
There are many free screenshot utilities available, in addition to the ones that come built into operating systems.
15
u/Setaganga Jul 01 '22
A sad amount of my errors are from variables being misspelled
116
u/megamaz_ Jul 01 '22
if 0 == 4im crying80
u/HarryTheOwlcat Jul 01 '22
If you're learning Python, give f-strings a try. They are very powerful and easier to read than other methods.
https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings
13
u/cginc1 Jul 01 '22
lol everything about the code you can see in this image is terrible
60
u/TheBrainStone Jul 01 '22
Avoid one letter variables. Give them descriptive names. Costs you not more than a minute to write but saves you hours relearning your code.
7
u/Dark2Fire Jul 01 '22
I have question for you will 0 ever equal 4?
If so let me know so I can use that as the basis for my power generator.
4
u/devhashtag Jul 01 '22
I often mistype o as 0 and vice versa. My brain just can't handle it properly
2
u/LeanderT Jul 01 '22
Good code doesn't need to be correct, it needs to be readable. Maintaining code cost more than the initial effort to write it.
So for the love of God, start naming your variables and functions to something that describes what it actually does.
Otherwise it's just an unreadable mess. As you have just experienced first hand.
60
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jul 01 '22
Image Transcription: Code
[A photograph of code on a computer screen, with parts of some lines cut off. The visible code is as follows:]
[Highlighted code begins:]
[Highlighted code ends:]
[In a non-monospace font:]
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
8
u/idothisinmysleep Jul 01 '22
Yeah that’s a pretty bad variable name
9
u/Elijah629YT-Real Jul 01 '22
0 = o == 4
1
u/Downtownender shameless Sep 30 '22
Someone explain, smol brain not workin’
3
u/xWrongHeaven Jul 01 '22
Did muscle memory kick in when you unsuccessfully tried typing "named"?
1
u/bistr-o-math Jul 01 '22
Bad eyesight? Or did you work with a different font?
2
u/Miserable-Plate-1038 Jul 01 '22
The fuckk....
2
u/Enum1 Jul 02 '22
There's a ton of bad naming here.
`r`, `o`, `sub`
I'm kinda glad we can't see more of the code.
1
u/[deleted] Jul 02 '22
If you're using an IDE like PyCharm, you can save yourself a lot of time finding bugs by adding breakpoints to your program and running your code in debug mode: https://www.jetbrains.com/help/pycharm/debugging-your-first-python-application.html
This will let you pause the execution of your program wherever you want, inspect the value of each variable, and run the program one line at a time.
1
u/mojo2600 Jul 02 '22
I wonder how many hours I spent just searching vor the ; that should be a , or typos in variable names.
1
u/sfboots Aug 16 '22
Reminders of some code I inherited. The variable was "l". The original author used an editor where "l" and "i" and "1" were quite different. But not so much in the one I was using. took me an hour to finally try renaming the variable and seeing what showed up as the problem.
1
u/Bowiemtl Sep 29 '22
never name a variable a single letter, especially an O. Only exceptions should be xyz and ijk for example where it's obviously for simple iterating
1
u/noonagon Nov 07 '22
ah yes, 0 vs O
1
u/ThusSaidTheOracle Nov 13 '22
That's why the zero has a stroke through it FFS lol
0
u/Gh0st1y Jul 02 '22
Bad variable naming or maybe just bad attention to detail? Theres a slash in the zero for a reason after all
0
u/[deleted] Jul 01 '22
[deleted] — view deleted comment
0
u/[deleted] Jul 04 '22
[deleted] — view deleted comment