Technical
A Year Two Python Refactor: What I Changed In My Script Style
Looking at the Python I wrote in April 2025 versus April 2026 I can see four habits that changed. None of them are dramatic. All of them compound.
The business problem is maintenance. Scripts that are fun to write are not always fun to revisit six months later. A year of daily writing exposed which habits aged well and which did not.
Change one: fewer classes, more functions
Year one me reached for classes early. Year two me writes a function first and only upgrades to a class when state or polymorphism actually shows up. Most scripts never need a class.
Change two: dicts over dataclasses for throwaway shapes
Dataclasses are great for code that lives for years. For scripts that run once a week, a dict with good keys is honest about its short life.
# Year one
@dataclass
class Row:
name: str
value: int
# Year two
row = {'name': name, 'value': value}Change three: early returns over nested conditions
I used to write deeply nested if-elif trees. Now I write guard clauses that return early and leave the happy path unindented.
def validate(user):
if not user:
return False, 'missing user'
if not user.email:
return False, 'missing email'
if user.banned:
return False, 'banned'
return True, 'ok'Change four: print before logging
For scripts under 200 lines, print is a valid debug strategy. I no longer reach for logging until the script starts running unattended on a schedule. Ceremony at the start of a file is a tax on the first hour of work.
What stayed
Type hints on function signatures. Those pay back every time Claude reads my code.
The lesson
Style is not dogma. It is the accumulated shape of your recent pain. See PEP 8 for the base. Then let your habits drift toward what saves you time this quarter.
RELATED READING
The Consulting Shift I Am Making In Year Two
After a year of writing and building, my consulting practice is changing shape. Shorter engagements. Sharper outcomes.
ReadThe Frontend Shift: Shipping Less JavaScript In Year Two
A year ago I reached for Next.js for everything. This year I often reach for nothing.
ReadThe Serverless Lesson I Would Write On A Sticky Note
After a year of shipping serverless projects, one rule explains most of the wins and all of the losses.
Read