I was at a bus stop dropping my wife off one morning, and she remarked that a lot of the buses that stopped were somewhat full. This was a stop I was intimiately familiar with and while I knew the frequency of buses intimately well, she was becoming increasingly frustrated because she had a train to catch.
I told her not to worry because I knew that you could always find a bus sooner or later.
She then suggested that we could’ve used a different stop that was only a little further away from where we currently live. And she was right. The other stop was earlier in the route and we would’ve had more chances to find better seating. This had not occurred to me, because I had always used our current stop because it was nearer to where I used to live.
Eventually we did find a bus and she was on her way but what I realized that I had made a fundamental mistake of not accounting for change in context, i.e. the fact that we now live a lot closer to these two stops than we once did and there was a more efficient route we could’ve taken.
I am a creature of habit and when you’ve used something for three years constantly optimizing it and understanding its ins and outs, it is difficult to think of other solutions that may be more viable.
I changed jobs about a year ago and I’ve had to change a lot of my old habits of Python development because, obviously we do things differently at this company.
I have brought over a lot of good habits that I developed at my old job, stuff like aggressively logging exceptions, using objects for functions with more than 5 parameters other such general elements of coding style that fixed a lot of issues with the codebases that I used to work with.
However, now the context has changed. Python has changed. For example, we cannot use .format() any more for our strings because we have f-strings now. We have for...else which cleans up a lot of “retry loops” conditions we need to implement. We of course use the := walrus operator which again, cleans up our conditionals leading to a more comprehensible codebase.
Linus Torvalds recently chewed out a Googler over re-using functions out of their original context and while harsh, his commentary does highlight the fact that while code reuse is great, we always need to consider the context that the code is currently being executed in. So much so that sometimes it is better (and perhaps cheaper) to rewrite large pieces of code because they may, if nothing else, save us from a ballooning AWS bill.
We cannot rely blindly on old habits no matter how strong our instincts may be and even at the most basic level of running tests for an old piece of code, we need to remember the context in which this piece of code is now executed.
This is why we need to keep learning and keep reading up on stuff, no matter how difficult Google may be these days. We also need to go back and re-evaluate not only documentation of the code, but also the coding style it was written against. We need to re-evaluate for the current team that will be using those standards and the APIs and databases it may be interfacing with because those too, are constantly changing and seeing improvements of their own.
Habits are great. Habits are a good bit of standardization that leads to consistent code that is going to be easier to maintain in the future.
However, tunnel vision is a very real danger we face if we don’t re-evaluate those habits every once in a while.
Remember, when all you have is a hammer, every problem is a nail and that context is king. Re-evaluate your test cases. Re-evaluate your coding standards and re-evaluate what you consider good coding practices because you may just be missing out on a faster, more efficient bus route to your next destination.







