Iām writing some new code and one of the pleasures (dismays?) of
starting a fresh codebase is defining your āinfrastructureā. Loading
logging. Defining a configuration standard. Integrate CI and creating a
runbook template. Why shouldnāt I revisit my code writing too?
Iāve known for the past few years Iāve written Python that Iām only
using the basics of the language. I donāt use static types or
decorators. I avoid classes and of course unit testing is a chuckle. Iām
not going to add all of that into my workflow right now, but in the past
Iāve always been good about composing my infrastructure components to
ensure that down-the-road I donāt have to refactor a huge chunk
of a project to allow for a basic change ā so Iāll improve my Python
writing.
Areas of focus:
Use data models, https://docs.python.org/3/reference/datamodel.html.
Specifically special methods and other core features beyond the typical
dicts and lists. If I compose my data to an object that supports these
functions I can more easily pass it through logic ā or even limit the
amount of logic handling Iāll have to do!
Catch exceptions (and handle them!), https://docs.python.org/3/tutorial/errors.html. This is
only feasible since Iāll be doing a better job managing what data gets
stored in my objects. I find myself looking to merge datasets often
enough, that Iāve gotten use to just using a couple of iterators to dump
data blindly to a new dict. No more blindness!
Using list comprehension for managing logic, https://www.geeksforgeeks.org/python-list-comprehension-and-slicing/.
I understand this isnāt a new paradigm of coding, Iāve pondered if it
goes against Pythonās readability advantages, but I find that in my
workflow I enjoy it. Iām tired of spending time buried in tabbed
iterations.
Thatās all. Just a couple of points. Iām not an expert, but I write
Python all the time, yet aside from def and some clever
for loops I rarely find myself pushing into new
territory.