In my last post, I presented Python and it’s strengths. To be fair, I’d like to continue and share my thoughts about some its weaknesses.
1. DOCUMENTATION REVISITED
Python programs are poorly documented. On of the goals of Python is that the code should be self-documenting; programs are thus written in such a way that you don’t need comments. This is a wonderful little theory that doesn’t work so well in the real world. For anyone who has had to scroll through code, good luck trying to understand it. A little judicious documentation goes a long way in explaining algorithms and finding bugs.
2. WHERE’S THE WHITE SPACE?
Another Python standard that is white space is discouraged. This results in code that is extremely difficult to read. I understand the goal is to limit the size of each function to one page but extremes are dangerous and I would like to see a compromise of limiting the size and function and including proper comments. In fact the whole point of Sphinx is to convert code comments to code documentation. Sphinx can’t work unless there’s code comments.
I have noticed that a lot of Python code is defensive. By that I mean the code assumes correctness and that any bugs will be easy to find at run time. Again this is another wonderful little theory that doesn’t work out so well in the real world. A lot of bugs are a result of data structure corruption; the quicker code can detect this corruption the easier it is to find and fix bugs. Exceptions are standard Python feature and are great. Asserts are another feature that is unfortunately not commonly used. Asserts should be used for assumptions that should “never” happen. They are in essence self documenting and help greatly in error detection and debugging.
Because it is an interpreter Python will obviously be slower than compiled code. But Python is implemented in C and it creates “compiled” .pyc files. The performance will not match programming languages like C.
For those Python experts out there, what weaknesses have you experienced? I invite you to share your thoughts about my analysis.