On 6-Feb-09, at 12:51 PM, Stephen J. Turnbull wrote:
The inconsistency is quite small. In fact, in English colons and semicolons have both different syntax and different semantics, and the same is true of Python. In English, the semicolon expresses a conjunction of two not necessarily related sentences. Python is the same, except that since we all run von Neumann machines, conjunction implies sequencing. The colon, on the other hand, represents a relationship of some kind. A native-speaker simply doesn't write things like "The sky is blue: mesons are composed of two quarks." (Well, the coiner of the work "quark" might, which is the exception that proves the rule.) And the same is true in Python; the code fragment preceding the colon controls the statement (suite) following it. Thus, the apparent isomorphism of the semantics is quite superficial, almost syntactic itself.
Syntactically, in English a semicolon takes two sentences to conjoin. A colon, on the other hand, must have a full sentence on one side or the other, but the other side may be almost anything.[1] Similarly in Python: both what precedes the semicolon and what follows it must be complete statements, while what precedes the colon must be a fragment, and what follows it is a complete statement (suite). So the colon and semicolon do not have isomorphic syntax, either.
>
In fact, the semicolon is indeed redundant, as it is precisely equivalent to a newline + the current level of indentation. This kind of redundancy is quite unusual in Python, so I wonder if the BDFL might regret having permitted semicolons at all, as he has expressed regret for allowing the extended assignment operators (eg, +=).
I have no problem with the different semantics of colons and
semicolons. What I do have problem is that colons are mandatory but
semicolons are optional, while both are completely redundant. Colons
are redundant too because they are precisely equivalent to a newline +
a deeper level of indentation.
In colon-less Python, the control fragment is insufficiently divided from the controlled suite. Just as in English, a bit of redundancy to reflect the hierarchical relationship between the control structure and the controlled suite is useful.
I think indentation is sufficient to divide them. A block indented one
level deeper is always associated with the previous one level
shallower code. We even indent line continuation to reflect such
relationships.
In Python, the same character is used, which is helpful to those whose native languages use colons. This is indeed good design. It expresses, and emphasizes, the hierarchical structure of the control construct, and does so using a syntax that any English-speaker (at least) will recognize as analogous.
The hierarchical structure is expressed by indentation. Colons simply
(over)emphasize it. That's why I think they are redundant. Choosing
the colon character is fine. Making it mandatory is bad.
I don't expect to convince you that the required colon is good design, but I think it puts paid to the notion that colons and semicolons are isomorphic. It is not true that what we conclude about semicolons is necessarily what we should conclude about colons.
Forgive me if I do not fully understand your point, but it appears to
me that you conclude semicolons are optional because they are
redundant. I think the conclusion is precisely the same for colons.