Opportunity missed by Python ?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Nov 14 22:10:34 EST 2011
On Mon, 14 Nov 2011 15:59:39 -0800, DevPlayer wrote:
> What I don't get is, having seen Python's syntax with indentation
> instead of open and closing puncuation and other -readability-
> structures in Python's syntax, is if someone is going to invent any new
> language, how could they NOT take Python's visual structures (read as
> readability) and copy it, whether it be a compiled language, explicidly
> typed checked or whatever underlying mechanism they want to make that
> code executable.
Because sometimes people have priorities other than readability. Or they
actually *like* braces. (I know, crazy!)
In fairness, the significant indentation is not all peaches and cream, it
has a dark side too. For example, the difference between visually
indistinguishable spaces and tabs can be meaningful (in Python 2, your
code may be broken if you mix spaces and tabs; in Python 3, the compiler
will give you an error). If you work in a noisy environment that eats
whitespace, such as crappy web forums, people using HTML email, editors
with unfriendly word-wrapping rules, and the like, you might miss having
braces. I occasionally see emails with code looking something like this:
print(something) while x < 100: print(something_else)
x -= 1 if x % 2 == 1: some_function() else: another_function()
third_function() print(x)
So the "off-side rule", as it is called, is not uncontroversial.
Languages developed by old-school language developers or academics, like
Google's Go language, tend to be very conservative and hence require
braces or even semicolons.
http://en.wikipedia.org/wiki/Off-side_rule
So many people keep asking for braces in Python that one of the
developers (Guido?) gave in and added it to the language. Just run
from __future__ import braces
at the top of your file, or at the interactive interpreter, and you're
done.
My own opinion is that the time I save with significant indentation is a
hundred times greater than the time I lose due to mangled code without
braces. So I consider Python's design a big win, but other people may
make other value judgments.
--
Steven
More information about the Python-list
mailing list