Python isn't a silver bullet

Where I evaluate my experience with Python
Published on Sunday, 14 May 2023

How did it start

Back at school, our first dive into code was MoscowML (for some unholy reason). Strictly functional language, and not a lot of fuzz. We learned how types mattered, and we learned how to get something working without loops and control flow. An interesting exercise, but not really what I was there for.

Later on, we were taught Java as the object oriented flavour. It took quite a while to get accustomed to all the new syntax and all the boilerplate. It was back in Java 5 times, if I recall correctly, so "Syntactic Sugar" did not exist 😅

I was coming to terms with Java and starting to get somewhat productive, but all of the boilerplate was really bothering me. That was until fellow students started talking about Python. Now, I didn't really have the mental capacity or appetite to take on another language at this point, and Python wasn't the only thing being discussed. There was also talk about Haskell and Lisp, so I tuned it out.

Once I did have a look at Python, though, I was instantly in love!

  • Don't do classes unless you want to
  • Who liked curly braces and semi-colons anyway, just use indentation
  • Want to use the same variable to store everything? You totally can. Typing is super loose
  • No need to wait for a compiler and some arcane toolchain, that only bloated IDEs knew how to wield (when the stars align), just write plain text and run it through the interpreter. Easy peasy!

This was glorious! I could get things done without worrying much about whether it made sense. I'd just run it and see how it worked out!

Web development was the next thing to attack, and learning all of that at once was tricky. HTML, CSS, JS, frontend, backend, authentication, database access, etc. So much ground to cover. Luckily, there was this framework, Django, which came with all batteries included, and it was so easy to get started!

I did some Django for fun, I did some volounteer work with Django, I got a part-time job doing Django, and then a full-time job, that I've held down for 7 years now, mostly doing Django.

If you've read my other post about Django, you'll know that the honeymoon period has certainly come to an end. Scaling Django was hard, due to the ORM coupling, but Python started to become problematic too!

As applications grow large, it is important to have maintainable code. Part of that is to write SOLID code and follow all the best practices, etc. With Python though, there is the matter of it being an interpreted, dynamic language, rather than a compiled, statically typed language. This is exactly what got me started so quickly! Just write it up and run it and you're great. But as applications become bigger and bigger, bugs creep in, and they are sooooo much harder to track and squash in dynamic code. Or rather, once you squash the bug, you want to be sure that you didn't inadvertantly cause other bad things to happen.

With Python, the message is clear: write tests! And of course I did that. Many tests. Thousands of tests. But the thing is; with statically typed languages like Java or C#, there is a whole category of tests, that I wouldn't have to write, namely, tests that verify that interfaces are respected, and that the correct types are used in all places. That is simply checked by the compiler. In Python, we learn to write very defensive, duck-typing code, which will just try to do the right thing, even if it receives the wrong types. But that only takes me so far.

With a test-suite of 5000 tests on top of a project with hundreds of thousands of lines of code, we still see thing breaking in completely arbitrary ways. Sure, not all of that is Python's fault. None of it really, because there is always things we could have done to prevent it, but my point is that compiled, statically typed languages are starting to seem really appealing.

The other thing about the static vs dynamic talk is that all of the design patterns you'll read about from the last 20 years, mostly all assume that we're working with static classes and interfaces. There is so much power in that, which is completely lost to Python 😕

So all in all, my conclusion here is that while Python was super easy to learn, which was great; I am now thoroughly disillusioned and have a pretty clear idea that my future is compiled and C# 😀

Blog Logo

Hi! thanks for dropping in to pick my brain

I write on this blog for my own benefit. I write because I like to, and because it helps me process topics. It is also my own little home on the web and a place for me to experiment.

Since you're here though, I'd love to hear your thoughts on what you've read here, so please leave a comment below. Also, if you like what you read and want to give a small tip, fell free to:

Buy Me A Coffee