What to do when working on a Python project


Sometimes people ask me what they should learn about if they want to learn to be a better programmer. (These are mostly scientists who write programs only for their own consumption.) My answer usually surprises them:

  1. Learn a real language. That can be Python, R, or whatever, so long as it’s not Matlab. (A note about Matlab: I will never say that Matlab is not useful or not good, but I will say that Matlab is not a “real” programming language. Programming is a lot about abstraction: you write functions and more functions. In Matlab, every function has to be in its own file with a name that matches the name of the function. This is not a good paradigm for hierarchical organization of code. If you don’t understand what that means, see #1.)

  2. Use version control, probably git and github (or bitbucket). MIT students get free private repositories, which is sweet.

  3. Write unit tests. The more I write code the more I realize I code have saved time by writing the tests first.

To get more advanced around Python, I found this post by Jeff Knupp to be really useful (if a bit dated). Python, for being so nice in some respects, has some really confusing parts (for me, that’s project dependencies and project file structure). This post was one of the best ways I saw to clean that up. It taught me about tox, and I used it as a guide in setting up a recent project.

It’s tempting to think that the way to get better is to dive into the sexy stuff. (I just learned that Python has macros, waaaa.) But it’s mostly about this bread and butter!