this post was submitted on 24 Apr 2025
64 points (94.4% liked)

Python

7095 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 0 points 3 weeks ago (1 children)

That's why there's type hinting, unit tests, and doc strings. I don't need to guess what the type is intended to be, I can see it.

[–] [email protected] 1 points 3 weeks ago (1 children)

But that's an extra step of logic u must hold in ur head while trying to understand 12 other things.

[–] [email protected] 1 points 3 weeks ago

What's the extra logic?

if x:

This always evaluates to True if it's non-empty. There's no extra logic.

If you have to keep 12 things in your head, your code is poorly structured/documented. A given function should be simple, making it plainly obvious what it's intended to do. Use type hints to specify what a variable should be, and use static analysis to catch most deviations. The more you trust your tools, the more assumptions you can safely make.