Compare source code

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Fri Nov 5 07:36:44 EDT 2010


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:

>> I really like "indentation as structure" (code is more compact and
>> clearer), but I really hate that it relies on me putting the right
>> spaces at the right place.
>
> Er what? You really like indentation as structure, but you don't like 
> putting in the indentation?

Exactly. I want the extra safety belt of not relying on spaces only.

>> for i in ... :
>>     for j in ... :
>>         whatever(i,j).
>>     .
>
> How is that different from this?
>
> for i in ... :
>     for j in ... :
>         whatever(i,j)

At this point exactly, there's no way to know what the indentation of
the next line should be. My example above explicitely indicates the next
line should be at the same level as "for j ...".

Now suppose that, at this very place, you have to paste some other
if/for/while block whose original indentation is not exactly aligned
with the fragment above. No way to decide automatically how to align it
(under "for j"? under "whatever"?).

The dots I suggest are nothing more than tiny closing braces.

> What's the point of the dots? Is that just to save you from having to hit 
> shift-tab (or whatever your editor's decrease-indent command is)?

Redundancy. I often have deeply nested constructs, that I sometimes need
to move around. A real pain, compared to brace-based languages, where
constructs are explicitely terminated (i.e., not implicitely by the
start of the next construct). Have automatically indented source is a
useful and quick check.

>> No lost vertical space (except when I decide it), no ambiguity. 
>
> What lost vertical space are you worried about?

You've cut the part of my message where I say that python's (vertical)
compactness is one of its strong points.

>> It looks to me like the exact opposite of ':'. End-of-line periods
>> (or exclamation marks) would let tools reindent correctly in all
>> cases. I don't think it conflicts with any other syntax.

> for i in ... :
>     for j in ... :
>         n = 2.

You're right, I forgot this one (probably because I never use this kind
of elision). No big deal:

for i in ... :
    for j in ... :
        n = 2.
        m = 3. .
    for j in ... :
        f = 2 .
    ...

-- Alain.



More information about the Python-list mailing list