Original title: Escaping Your Java Habits in Python: Writing Clean, Pythonic Code
As engineers, many of us migrate between languages. Fun fact: 20 years ago - what was the first language I was ever certified in? Java. But now, a dozen languages later, I want to pull my hair out when I feel like I’m reading Java code inside a file that ends in a “.py” extension. If you’ve spent significant time in Java, it’s natural to bring those habits along when coding in Python. Unfortunately, some of those habits can lead to over-engineered or awkward code that doesn’t at all feel Pythonic. Worse: your habits may be contributing to bugs, and (worse yet:) slowing down code review. Not to bring shame, but to improve everyone’s lives: I think these patterns are worth calling out — especially for developers making the jump from Java to Python.
- Overcompensating for Dependency Injection (DI)
The Java mindset
Java is not particularly strong at dependency injection (DI). Without additional frameworks (e.g. Spring, Dagger, Guice, etc.), it’s actually super diffic