Advent 2021: Python
This blog is part of the 24 posts long series "Advent 2021":
- Advent 2021: Intro (December 01, 2021)
- Advent 2021: C++ (December 02, 2021)
- Advent 2021: C# (December 03, 2021)
- Advent 2021: Python (December 04, 2021)
- Advent 2021: Go (December 05, 2021)
- Advent 2021: TypeScript (December 06, 2021)
- Advent 2021: CMake (December 07, 2021)
- Advent 2021: Django (December 08, 2021)
- Advent 2021: Angular (December 09, 2021)
- Advent 2021: Flask (December 10, 2021)
- Advent 2021: gRPC (December 11, 2021)
- Advent 2021: GraphQL (December 12, 2021)
- Advent 2021: XML & JSON (December 13, 2021)
- Advent 2021: Matplotlib, Pandas & Numpy (December 14, 2021)
- Advent 2021: Linux (December 15, 2021)
- Advent 2021: Ansible (December 16, 2021)
- Advent 2021: SQLite (December 17, 2021)
- Advent 2021: Catch2 (December 18, 2021)
- Advent 2021: Zstandard (December 19, 2021)
- Advent 2021: ZFS (December 20, 2021)
- Advent 2021: Thunderbird (December 21, 2021)
- Advent 2021: Visual Studio Code (December 22, 2021)
- Advent 2021: Blender (December 23, 2021)
- Advent 2021: Open source (December 24, 2021)
Yesterday I wrote about C#, the second compiled language I use. Time for a change and a “proper” scripting language I’ve used a lot over the years: Python. Python was and remains my goto-language if I need a one-off script, but also for any kind of “data processing” task. Convert a thousand XML files to JSON and put them into a database? It’s Python time!
Being easy to use comes down to a few factors, and there are two main reasons for me to use Python. First and most important, the language is easy to read. I’ve been looking at scripts I wrote 10 years ago and I have little trouble understanding what I wrote and what is going on. Python has evolved over the years but at the core it remains a simple language, thanks a lot to the “only have one way to do things” mentality.
Second, and at least as important, is the incredibly large ecosystem of libraries, especially around databases, file formats, and web technology. If there’s any mature C or C++ library, chances are that there is a wrapper available for Python. The ease of use of Python libraries can’t be overstated: You want to quickly make a web request to download some data? You’ll be hard pressed to do it with less code than a Python script using requests. In fact, for web development, it’s actually game over because many libraries are Python-first, if not Python-only.
But it’s not only that, Python makes it incredibly easy to prototype something and grow it without creating one large mess. A welcome development was the introduction of type hints which in my opinion is a huge improvement when you grow your code, as I’m a big fan of good types. Python did a great step forward here by introducing gradual typing (we’ll learn about another language with the same feature later in this series) which allows you to add types where it matters. Meaning:
# Probably not going to add types here unless
# you're a perfectionist
def get_greatest_common_denominator(a, b):
...
# A-ha! It's a tuple that's expected
def resize_image(src: Image, size: tuple[int, int]) -> Image:
...
For my bigger Python projects like Liara this has been super helpful as it makes picking up old code even easier. It’s great to see features of such impact coming to a – by now – rather mature language like Python.
I’m incredibly excited to see where Python is headed. The recent years have seen lots of good improvements and the future is definitely bright. Thanks to machine learning which nearly universally uses Python the amount of new developers and interest in the language is at an all time high, and it feels like a great time to be a Python developer!