What’s One Python Practice You See That Should Be Illegal? #162830
Replies: 8 comments
-
|
I’ll go first. So picture this: I was in full “10x dev” cosplay hoodie up, lo-fi beats on, terminal dark as my sense of test coverage. I wrote two API functions that were so identical they could've filed taxes jointly. Did I refactor? Then my senior rolled up on the code review like Gordon Ramsay inspecting a microwave steak.
Bro said it so calm, but I felt it in my ancestral Git commits. Anyway, I pulled myself outta tutorial brain mode, refactored the logic into a nice helper function, sprinkled in some type hints, maybe even threw in a docstring for ✨vibes✨. Felt like I just unlocked the Pythonic Sharingan. …until I ran it. Instead of reusing the one I already had, I summoned a fresh ORM query inside the helper. Like I was trying to DDOS my own database just for funsies. Round 2 of code review:
At that point, even Git was like “nah bro this one’s on you.” Moral of the story:
Your turn. |
Beta Was this translation helpful? Give feedback.
-
|
Lmao 💀 been there! Nothing scars you like opening a repo and finding a 500-line function named process_data_final_final2(). One thing I will ban from my projects — from module import *. Absolute chaos. It's like inviting strangers into your namespace with no name tags. Suddenly you're using a function and have no idea where it came from. Debugging turns into detective work 🕵️♂️. Also, mixing tabs and spaces? That’s not just a bad habit — that’s Python heresy. Your code might look fine, but then throws errors like it’s haunted 👻. Set your editor to show invisible characters. Trust me, future-you will thank you. Worst offender I saw: someone used eval() inside a loop to dynamically run stringified user input. Like, bro… are we building a calculator or writing malware? |
Beta Was this translation helpful? Give feedback.
-
|
One time I wrote a Python script for a project and, genuinely not sure what I was thinking, I put the entire thing into one giant function. I’m talking hundreds of lines. No structure, no helper functions, just this endless scroll of logic with variables popping in and out like it was normal. Debugging it was a nightmare. I’d fix something at the top, and five minutes later I’d realize I broke something 200 lines down. At some point I added from module import * because I was “trying to keep it clean,” which somehow made everything less clear. The worst part is, I remember proudly submitting it thinking it was clean because “it worked.” I’ve started breaking things into smaller functions now and being way more intentional with what I import. Still learning, but that experience taught me fast that just because Python lets you write messy code… doesn’t mean you should. |
Beta Was this translation helpful? Give feedback.
-
|
Hard coding secrets directly into Python source code can cause numerous security vulnerabilities that can corrupt your IDE. |
Beta Was this translation helpful? Give feedback.
-
Love this question 😂 — every Python developer eventually discovers some truly cursed code patterns. Here’s one practice I’d nominate as “should be illegal”: USING Example of the crime: user_code = input("Enter something: ")
result = eval(user_code)
print(result)Why this is terrible:
Safer alternatives:
HONORABLE MENTIONS (ALSO ILLEGAL) 1)
Better: from module import useful_function2) One 500-line function
Better: 3) Catching every exception blindly try:
do_something()
except:
pass
Better: except ValueError as e:
print(e)4) Mixing tabs and spaces
Better: SHORT RULE OF THUMB 🐍 If code is:
…it’s probably a Python crime. Clean, simple, readable code will always win. Curious to hear others’ horror stories too — Python has no shortage of creative chaos 😄 |
Beta Was this translation helpful? Give feedback.
-
|
🚫 The 'Illegal' Practice: Bare 'except' in try-except statement This is when someone wraps a massive block of code in a try/except block but doesn't specify which error they are looking for. # DO NOT DO THIS
try:
user_input = get_data_from_api()
process_calculation(user_input)
save_to_database(user_input)
except:
print("Something went wrong!") # But what? And where? Why it should be "illegal":
✅ The "Legal" Way: Specificity You should always catch the specific exception you expect. If you are worried about a connection issue, catch the ConnectionError. If it’s a math issue, catch ZeroDivisionError. try:
value = 10 / 0
except ZeroDivisionError as e:
logging.error(f"Math fail: {e}")
except Exception as e:
# This is the "Safety Net" - it catches most errors but
# still lets SystemExit and KeyboardInterrupt through.
logging.error(f"Unexpected error: {e}") |
Beta Was this translation helpful? Give feedback.
-
|
One practice I find particularly harmful is using mutable default arguments: This is a hidden trap — the list is created once and shared across all calls. For example: The correct way: Another practice that should be illegal: using except: pass to silently ignore all errors — it hides bugs and makes debugging a nightmare. |
Beta Was this translation helpful? Give feedback.
-
|
Using mutable default arguments: def add_item(item, lst=[]):
lst.append(item)
return lst |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I’ve been learning Python for a while now, and I’ve started to notice something…
Some Python code out there is STRAIGHT-UP ILLEGAL (or at least it should be).
I’ve seen things like:
I get that everyone writes code differently, but some patterns just feel cursed.
💬 So I wanna ask:
What’s one Python practice you’ve seen that should be straight-up banned?
Doesn’t matter if you’re a beginner or a pro if you’ve ever looked at some Python and thought “Nah, that ain’t right,” drop it below:
I’m learning, and I wanna learn the right way minus the code crimes 😂
Let’s air out the dirty Python laundry 🧼🐍
Beta Was this translation helpful? Give feedback.
All reactions