Indentation for code readability

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Fri Mar 30 09:23:40 EDT 2007


On Fri, 30 Mar 2007 02:04:45 -0700, DE wrote:

> Hello,
> 
> Here is what I do in C++ and can not right now in python :
> 
> pushMatrix()
> {
>      drawStuff();
> 
>      pushMatrix();
>      {
>             drawSomeOtherStuff()
>      }
>      popMatrix();
> }
> popMatrix();
> 
> The curly brackets have no functional meaning 
> but increase the readability significantly. 

I don't understand why you are indenting 
the function calls. What does the
indentation and spacing signify?

Or, to put it another way:


    I don't understand why you 
    {
        are indenting 
        {
            the function calls. 
        }
    What does the
    }
    indentation signify?



> I want to be able to do the same thing in
> python. Since curly brackets are not available and indenting without
> an if or while conditional doesn't work, I have started to question if
> this is possible in python at all.

Thank goodness it isn't, in general.

But if you want people to point at you and laugh in the street, you can do
this:

pushMatrix()
if True:
    drawStuff();

    pushMatrix();
    if True:
        drawSomeOtherStuff()

    popMatrix();

popMatrix();



> Any ideas ?

Some people 
    have a strange 
        idea of 
    "increase 
readability".


-- 
Steven.




More information about the Python-list mailing list