Sitemap
Pythonic AF

Join our smart community of Python developers! This is your no-BS guide to mastering Python, deep dives, hot takes, clean code, dirty bugs, and everything in between. From automation to APIs, web apps to AI, we cover real world tips, performance tricks, and more.

Member-only story

7 Python Features That Make Your Code Worse

4 min read1 day ago

--

How much work would you expect invoice.total to do?

I’d expect it to read a value or do some arithmetic. If that line opens a database connection, fetches tax rates, and checks a VAT ID over the network, I’d want to know that before I put it inside a loop.

Python lets you write it either way. That’s where the design decision starts.

Read the full story for free here on Medium

Press enter or click to view image in full size
Canva

1. A property that makes API calls

person.full_name is a good property. The object already has the first and last names.

Joining them is cheap, and anyone reading the code can make a decent guess about what happens. An invoice total that needs fresh data from two services is a different story.

An invoice total that needs fresh data from two services is a different story. I’d call it calculate_total() or, if the implementation uses async I/O, await invoice.calculate_total().

The call gives me a reason to check what the method does before using it three times on the same page.

--

--

Python Monster 👑 | 8 years | Solving complex problems, optimizing performance & sharing knowledge | Writer | Coffee, coding & creating every day!

Pythonic AF
Pythonic AF

Published in Pythonic AF

Join our smart community of Python developers! This is your no-BS guide to mastering Python, deep dives, hot takes, clean code, dirty bugs, and everything in between. From automation to APIs, web apps to AI, we cover real world tips, performance tricks, and more.