Today I’m joined by Dane Hillard, lead web application developer at ITHAKA and author of Practices of the Python Pro. Dane is also a Real Python tutorial author.
In this interview, we discuss a variety of topics, including code complexity, Python package maintenance, and popcorn. So without further ado, let’s welcome Dane.
Ricky: Thanks for joining me for this interview, Dane. I’d like to start in the same manner we do with all our guests: how did you get into programming, and when did you start using Python?
Dane: Thanks for having me back! Real Python is a pretty nice place to spend some more time. Some of my first experiences with programming were the same for a lot of kids from the era of LiveJournal and MySpace—I was regularly customizing my profile page and theme to make sure my angsty ramblings looked their best.
Around the same time, I started doing some 3D modeling in Rhinoceros as a mostly artistic outlet, but it also offered some scripting capabilities that I tinkered with. A friend and I got pretty into Liero, and I went so far as to make a few custom weapons for us to play with. So in all, a geeky start coming out of a few tangential interests.
I learned C++ and MATLAB in school and spent my first internship and full-time job working in those languages. I picked up Perl along the way and managed to land my second job using it.
While learning a massive amount about SQL optimization there, I also started tinkering on some side projects with a friend. He was a big Rails guy, so I started getting exposure to Ruby. I’d been using PHP and then Spring to run a website for my photography and decided to give Rails a try next. The “coding by convention” paradigm didn’t quite click with me at that time.
When I finally decided I really wanted a nicer iteration of my website, I looked around for other web frameworks with popularity similar to Rails and ended up finding Django. Python’s been my jam ever since! It was a meandering path, but I like where it’s taken me so far.
Ricky: What Python topics are you most interested in these days?
Dane: Python package maintenance has been a focus for me recently. I maintain a couple of small open source projects like apiron and django-webmention, and I also maintain around a dozen packages internally at ITHAKA. Having a process that’s repeatable but iterable, and opinionated but flexible, has become really valuable.
It all comes down to the tooling! Forgetting to make changes in one or two packages results in more context switching later down the road, so although there’s still some repetitive tasks across packages, they tend to be more like recipes than reinventing the wheel for each package.
I’ve tried several of the solutions out there for dependency management, like Pipenv and Poetry, but I wanted something that could also stand up to the challenge of wrangling all the tooling involved in packaging, like pytest, mypy, Black, and Pylint, to name a few.
For the moment, I’ve settled fairly comfortably into a workflow using tox and
setup.cfg to manage most everything. I’m keeping an eye on
pyproject.toml as well.
Now that there’s some automation in place around all these aspects, I’m taking more time to think about the complexity of code. I talk a bit about this in my book, but knowing enough to write about something doesn’t mean it’s always been given the proper amount of attention in practice! I’m enticed by taking a look at the patterns we use across our organization and finding the right designs for those patterns that help us move forward more quickly and safely.
I’ve been using Radon lately for quick and easy access to Python complexity stats. I’ve quickly identified a few areas of code we touch often whose complexity would be valuable to address. We also use SonarQube for tracking some of this data. Everyone should also check out Anthony Shaw’s interview to hear more about the tools he’s making.
Ricky: As much as these interviews are about personal stories from members of the community, I also try to leave our readers with something actionable they can take away and apply to their code. So with that in mind, what practical tips can you give that most people might not be aware of?
Dane: You can significantly reduce the complexity of a lot of your code by replacing sets of conditionals with a dictionary mapping conditions to actions. I’m regularly surprised how much some code collapses using this refactoring.
Sandi Metz has a great talk, All the Little Things, about refactoring in the Gilded Rose kata. Metz talks about separating the reason for switching from the thing to do when switching. I highly recommend watching this and all her other talks.
Ricky: You’re a tutorial author here at Real Python but also the author of Practices of the Python Pro. What are you hoping people will get out of the book when they read it? What did you learn while writing the book?
Dane: This is a really good question. It’s easy to think that a book covers stuff someone’s been doing for decades, which I’m sure is true some of the time. I actually learned a ton while writing the book, though. It forces you to do some structured research and critically examine alternatives to your current understanding.
One of the biggest things I learned more about while writing the book was the concept of coupling. It’s common to hear that we want loosely-coupled code, but for me it wasn’t ever a very tangible idea.
I’ve come to think about coupling in object-oriented programming as the roles filled by objects and how objects pass messages to each other. This mental model uncovers a lot of awkward points in code, and that can often be proved by trying to write tests for those interactions.
You’ll see this heavily reflected in Metz’s talks—she’s originally a Smalltalk programmer, and these ideas can often be traced back to that group of folks.
Ricky: You’ve talked about coding for the common good. How have you been doing that so far, and do you have any ideas for the future?
Dane: I’m a firm believer in the power of collective knowledge. This is frequently done with open source software, but I think it needs to continue growing beyond that. Invest in Open Infrastructure is a great example a colleague shared recently. They’re not just saying, “Here’s a bunch of tech you can use,” but taking it to the next level and providing strategy, research, community, and more.
Ricky: Now just a few last questions. What else do you get up to in your spare time? What other hobbies and interests do you have aside from Python and programming?
Dane: I’m a singer/songwriter, but I haven’t written much lately. I’ve enjoyed learning to play some covers during the quarantine hours. I’ve got quite a few Iron & Wine and Alexi Murdoch songs under the belt. My latest favorites are “Older Chests” by Damien Rice and “Isles” by Fleet Foxes.
I’ve been doing a bit of food-related stuff here and there. I kicked off a sourdough interest before the pandemic, and I’m just getting back to it after moving across the state. I recently found out that nutritional yeast is one of the best popcorn toppings known to humankind, so definitely go try that. For me, it goes well with a bit of paprika, garlic salt, black pepper, and herbs.
Ricky: Thank you for joining me, Dane!
If you’d like to get in touch with Dane about anything we’ve talked about today, then you can contact him on his website or on Twitter.
If there’s someone in the Python community that you’d like me to interview, then leave a comment below or reach out to me on Twitter. Happy coding!