Python is awesome. Period.
Ok, nothing beats the feeling of security that strongly typed, statically compiled languages like C++ provide you with. But for some quick scripting, Python is my tool of choice. Python allows for some Lisp-like elegance. And the ease of network programming using twisted’s inline callbacks is almost as hard to believe as it is hard to understand how and why it works.
But not everybody may agree. In fact, some will reject Python on the basis of what is probably its most controversial language feature: indentation. White space with a meaning. Semantic white space has a few consequences:
Editing becomes a bit more awkward. In contrast to other languages, your editor can not infer the indentation of your current line of code from the context in all cases. This is the largest drawback by far. It slows us down and makes copy&paste more error prone.
It is harder to produce auto-generated code in Python. In C++ or bash any program essentially can be written as a oneliner. Be it a “do this for every file” or a 3D graphic adventure. Nevertheless, auto-generating Python code (maybe using C++? ;-) ) is an odd use case.
It simplifies coding style. And after two downers, this is where things get interesting. It complies with two principles stated in the Zen of Python:
Simple is better than complex.
There should be one– and preferably only one –obvious way to do it.
Overall, inconsistent coding style is nuisance. Specifically, in a language like C++ which comes with quite some technical noise. Here, clean code (in terms of coding style) can help you to decipher foreign parts of the code base much quicker, yet it often does not come for free (even if a well-configured code formater is used). In my eyes, forcing indentation on the programmer at least relieves us from defining a style for code blocks. Consider the alternatives:
The problem is a similar one for languages (e.g., Bash) that use
ALGOL-style code block delimiters. The
while-do-done lead to even more clutter:
Let us compare it to Python, which has one and only one simple way to write the code above (and even strips the code from the easily forgotten semi-colons):
So, will indentation ever be optional in Python? Could we get a dialect with braces? Let’s ask Python ourselves:
>>> from __future__ import braces ; File "
", line 1 SyntaxError: not a chance</pre>