PyDev of the Week: Geir Arne Hjelle

This week we welcome Geir Arne Hjelle (@gahjelle) as our PyDev of the Week! Geir is a regular contributor to Real Python. You can also find some of his work over on Github. Let’s take a few moments to get to know Geir now!

Can you tell us a little about yourself (hobbies, education, etc):

Sure. I grew up in a beautiful village on an island in the north of Norway. My family has since moved south, but I still go north and visit friends and enjoy the nature regularly. I’ve always enjoyed playing with numbers, so I quite naturally ended up studying mathematics at the University. I did both a Master’s and a PhD at the Norwegian University of Science and Technology in Trondheim. During the PhD, I also got to spend about a year in my favorite big city: Barcelona. To this day, I spend a week or two in Barcelona every year.

After my studies, I lived three years in St. Louis, Missouri doing a Post.Doc at Washington University. Then I moved back to Norway, and I’m currently living in Oslo working with data science, mostly using Python.

I spend a fair bit of my free time with programming as well. I write tutorials for Real Python and helping teach kids how to code. I enjoy being outdoors. In Norway there are great opportunities for going skiing in the winter, and hiking in the summer. At this very moment, I’m actually basking in the sun in a hammock in the forest just outside of Oslo. Finally, I should note that I love getting together with friends for a board game session.

Why did you start using Python?

Interestingly, it actually took me quite a while to get warmed up to Python. I have done some kind of coding almost my entire life. I got started with BASIC on the Commodore 64 back in the 80’s, where I think one of my proudest achievements was figuring out that GOTO was evil. I also remember hacking one of my games with the magic line IF PLAYER="Geir Arne" THEN SCORE=SCORE+100, which in a small way exemplified the power of knowing some basic programming (and the responsibilities that come along).

My first encounter with Python was at a summer internship, where I was working alongside someone who was quite involved with Python at the time. This was Python 1.6, and it already seemed quite powerful. At the time I was dealing with Java, C, and C++, and ironically the simplicity of Python confused me. How did it work without a `main()` method? And what really happens at imports? In the end, I went back to my braceful code.

I finally picked up Python again around 2012. At the time I was working with Matlab as a modeling tool. Matlab is great for doing what Matlab is great at, but I also started to feel some of its limitations. At an internal hackathon, a colleague and I wanted to create a tool to automate the generation of some reports, and we decided to try Python for the project. This time it clicked much better. I was really impressed by how easily and fast we could create the tool. At the next hackathon, we did a proof-of-concept showing how to integrate Python into the Matlab model pipeline. While we got some support from the higher-ups, this unfortunately ended at the PoC stage.

As a kind of New Year’s resolution for 2014 I challenged myself to learn Python more properly. Luckily, several things came together that year. I started a new job where I could use Python as my main language. I was also able to attend a few conferences, and got to learn more about both the community and the eco-system surrounding Python. The more I’ve learned, the more impressed I’ve become with the language design. The core of the language is quite simple and consistent, while being very flexible. At the same time, the supporting tools and packages have really matured the last couple of years. I see a big improvement, just in the relatively few years I’ve been using Python.

What other programming languages do you know and which is your favorite?

At this point Python is clearly my favorite, and the language I reach for when I need to be productive. However, there are some other languages that I have very fond memories of. During my studies, I first started using Linux and came across Awk. I picked up O’Reilly’s classic Sed & Awk book—mainly because of the weird animals on the cover—and became an instant fan. Awk worked very seamlessly with the whole Unix philosophy of piping small specialized tools together. In the end, I used Awk to create several small tools, including a small language for creating fractals that I used for my Master’s thesis.

I’m also very impressed with Scratch. While it may have the appearance of a toy language, it supports all the “serious” programming concepts. I’ve been involved in teaching programming to kids for some years now, and Scratch is an amazing platform for this. The kids are usually up and coding on their own within 5 minutes of opening the web page. Within one hour they have created their very own game. I have actually done a few semi-serious projects with Scratch as well. However, the main limitation I find is that proper data structures are not really well supported (and I still do prefer the keyboard for coding).

Finally, I hope to one day have the time to learn a pure functional language more properly. I guess the philosophy really intrigues the mathematical part of my brain. There is a fun project called Coconut, which adds functional programming syntax right on top of Python. Another platform I hope to have time learn more about at some time is Erlang and its modern cousin, Elixir. The scalability and concurrency features look really great.

What projects are you working on now?

I recently started working at a data science and machine learning consultancy. There I’m involved in a few different projects, ranging from building models for customer analytics to modeling soccer kicks based on video. Previously, I worked with the Norwegian Mapping Authority, where we were building a tool to help monitor how the Earth is tumbling through space. I really enjoy projects where I get to combine programming and modeling in interesting and useful ways.

Outside of my regular work, I’m doing the final touches on a couple of articles I’m writing for Real Python: one about how imports work (answering all my own questions from back in the day), and one comparing classes, context managers, and decorators. I was lucky enough to go to PyCon US this year, where I gave a presentation about keeping code modular using a kind of plug-ins. I’m polishing up the documentation and some of the code of my pyplugs package that provides these plug-ins.

Which Python libraries are your favorite (core or 3rd party)?

I’m very grateful to all the effort that been put into the Python data science stack over the years, and most of what I do does in some way involve numpy. This amazing library has really been at the center of Python becoming the go-to language for data science.

Let me also mention another less known library: pint is a package for handling units and physical quantities. It wraps around numpy so that you can add units to your arrays, or you can use it to do simple unit conversions directly. Did you know that 1 apothecary dram is about 0.14 ounces?

[python]
>>> import pint
>>> u = pint.UnitRegistry()

>>> ad = 1 * u.apothecary_dram
>>> ad.to("ounces")

How did you get started with Real Python?

At some point I came across Dan Bader’s personal blog, and really enjoyed his articles and insights. Then, early 2018 I heard Dan on the Python Bytes podcast talking about how he was taking over the Real Python website and that he was looking for contributors to help him write tutorials. I felt that it would be fun to challenge myself a little again, and at the same time maybe get to know more people in the Python community, so I reached out to Dan.

It’s been a fantastic experience working with the whole Real Python team. I didn’t have a lot of experience writing from before: I’d done some scientific writing, and I had worked on some teaching materials for kids wanting to learn to program. However, with support from the rest of the team, and especially our editor, Joanna, I feel much more confident in my writing now. Additionally, I’ve learned tons from my colleagues and from readers reaching out with questions and insights about our articles.

We were lucky enough to join JetBrains at their content creators booth at PyCon in Cleveland this May. It was great to finally meet many of my Real Python colleagues, that I until then only knew through Slack and their articles and reviews. Additionally, several readers stopped by to chat. I must admit that I’m still very humbled by other people reading the stuff I write, and even finding it useful.

I see you volunteer to teach kids coding. What have you learned while doing that?

Back in 2013, some volunteers got together and started the “Lær Kidsa Koding” movement in Norway. It is aimed at teaching kids to code, in many different arenas. At the moment, there is a (slow) push to get programming into schools, while there are also code clubs and code camps where kids can learn programming outside of school.

There are great tools available for anybody wanting to learn programming today. In the code clubs I’ve been involved with, we have mainly used Scratch, Micro:Bit, and Python. It’s been fun to also teach more specialized tools, like Sonic Pi for programming music, Processing for programming animations, and ComputerCraft for creating computers inside the MineCraft game and programming them.

Teaching kids (and really anybody) programming is a very rewarding experience. Especially being around when things click, and you see them get a new concept, squash a nasty bug, or simply realize the power they have with their newfound knowledge. Some of favorite moments have been:

  • seeing a kid finally figure out how to properly set up an electric circuit, and being so proud of making a LED light up that he ran around the room high-fiving everybody,,
  • watching a 10-year old stand in front of 200 professional developers, telling them how a Micro:Bit microcontroller works, and how to create your own compass app on it,
  • experiencing kids quickly develop actual understanding of the underlying logic, and being able to play with the parameters of their games to make it harder or more fun.

What challenges do you face when teaching kids / teachers to code?

I guess the main difference in teaching kids and others who have not been exposed to any earlier programming, is that I need to emphasize intuition over technicalities. In the beginning they want to see something happen, not be bogged down in a long lecture about variables, types, pointers and objects. With tools like Scratch and Micro:bit, it’s easy to get started, and just play around with the blocks to see what happens.

Then at some point, the kids either don’t know how to do something they want to do, or don’t understand why the program is not behaving the way they expect. Being able to add to their intuition and understanding at that point, is a really interesting pedagogical exercise.

Is there anything else you’d like to say?

I do marvel at the power of open source, and the community’s ability to come together and create tools and resources that make us all better and more effective programmers. I’m very happy to add my small contributions to this ever-growing pool. I think initiatives like your interview series are great for showing the diversity in the community, and how everybody can participate at a level that works for them.

Thanks for doing the interview, Geir!