M
Michael Chermside
richardc said:Im no expert but wouldnt you accept that Python has 'borrowed' FORTRAN's
fixed format syntax. I can only think of Python and FORTRAN off the top of
my head which use whitespace as part of the syntax.
Definitely NOT. Without addressing the question of HOW Python came by the
idea of using indentation to indicate block structure, it clearly couldn't
have been from Fortran, because what Python does and what Fortran does
are COMPLETELY different.
In Fortran, starting lines in particular columns is meaningful (as are other
particular characters in particular leading columns). In Python, particular
columns have NO meaning. In fact, I would venture to say that it is
NOT whitespace that is "significant" in Python... it's INDENTATION. The
distinction is significant, because humans are very poor at reading
whitespace (the presense or absence of it yes, but the amount is something
we're not good at reading), but we find indentation to be a *very* readable
way to mark block structure (in practically every language which doesn't
(like Fortran) prohibit indentation, it is a convention adhered to
universally ).
There's also the fact that "lines" (statements) are defined by line breaks
in Python -- but I rarely hear complaints about this, since most programmers
mentally chunk up code into "lines" anyway.
Of course, I'm not suggesting that whitespace is *meaningless* in Python
outside of indentation... Python is much like C (and many, many others) in
that regard. After all, in C "y=x+ ++z" and "y=x++ +z" are quite
different things. And in both Python and C "x=abc" is legal, but "x=a bc"
is not.
So I would say MOST languages make the presence or absence of whitespace
significant... and that's a good idea, since it helps humans "tokenize"
the code they read. Python uses newlines to indicate where new "lines"
(statements) begin... not usually a controversial convention. Finally,
most PROGRAMMERS use indentation to indicate block structure, but Python
differs from most languages in that the Python parser uses the indentation
level as syntax for blocks, while most languages don't. And Python
doesn't[1] care about the AMOUNT of white space (independent of indentation
level) which is a good thing, because humans find that difficult to
read.
-- Michael Chermside
[1] Unless you mix tabs and spaces. Don't do that. Use tabnanny if you
need to.