semicolon at end of python's statements

Chris Angelico rosuav at gmail.com
Thu Aug 29 05:52:19 EDT 2013


On Thu, Aug 29, 2013 at 7:39 PM, Alister <alister.ware at ntlworld.com> wrote:
> Yet no doubt you voluntarily indent your c code to make it readable?
> it wont take long before you find you don't even think about indentation
> and actually like it

Most of the time, in any language, I will indeed have indentation
matching the syntactic structure of the code (which is what Python
demands). But I like the flexibility of having the indentation under
_my_ control, not under the language's, because my rule is that it
should match the *logical*, not syntactic, structure. For instance,
here's how code looks that iterates over an array:

foreach (some_array, mixed val)
{
    //do something with val
}

And here's how it looks if I want to iterate over a filtered version
of the array:

foreach (some_array, mixed val) if (some_condition)
{
    //do something with val
}

There's no language support required. It reads like a Python
list-comp, simply adding a condition as part of the loop header. But
it technically breaks the indentation rules, and Python doesn't allow
this sort of thing. In Python, this particular example is probably
best done with a generator expression in the for loop, but there are
other cases where I combine two physical structural levels into a
single line and indent level.

ChrisA



More information about the Python-list mailing list