Member-only story
7 Python Features That Make Your Code Worse
The code gets shorter. Now try figuring out what it actually does.
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.
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.








