In my previous post, I outlined how Python makes development a lot faster.
Unfortunately, Python’s lack of a static type checker can really hinder development in large applications.
As a great example, I was working on some slightly older code just a few days ago. This code had not been touched in probably six months to a year.
I set a member variable of a class to False. Unfortunately, I did not realize this same-named member of the class was actually a function.
So later on in the code, something tried to call my False as a function. This probably took anywhere from 15-60 minutes to debug.
This is a potentially big problem with large applications. There is no Python type checking; the language will gladly allow you to overwrite just about anything with a value of your choice.
So Is Python Not Good for Large Applications?
This leads several to claim that Python is not a good language for a large application. Instead, leave that to the “big boys” like C++ or Java.
If you need better performance than what Python provides, I can understand using C or C++. But if the main objection is static type checking, there’s a great solution for this:
Well-written unit tests.
With decent code coverage and well-written unit tests, you should not have to worry about Python type checking.
Unit Testing to Improve Code Quality
Ironically, spending time unit testing to some degree contradicts my claim that Python is a fast development language. If you’re writing unit tests, you aren’t going to develop (initially) as fast. Over time, however, you will be faster due to less time spent troubleshooting.
This means if you are writing a very quick script to debug, perhaps you should not care about Python type checking or unit testing.
If you are developing a bigger application or something that will be around for a while, it’s probably best to go ahead and write unit tests.
Some might say this defeats the purpose of fast development. I would argue that bigger applications should be wrapped with tests anyway. This is regardless of what language you use.
Python just happens to make unit testing a lot easier than some other languages.
So the next time someone complains that Python isn’t good for large applications, ask if they have unit tests around their code.
While Python does have a static type checking problem without tests, any large application should be wrapped with tests to catch these and other types of errors (like run-time errors).
Besides, who really wants to wait several minutes to verify every little change?
Use unit tests to your advantage!