Using Python -t ?

5 messages Options
Embed this post
Permalink
Glynn Clements

Using Python -t ?

Reply Threaded More More options
Print post
Permalink

As some people seem to have trouble with indentation, I'd like to
suggest that the wxgrass script should be changed to use -t, or even
-t -t:

       -t     Issue  a  warning  when  a source file mixes tabs and spaces for
              indentation in a way that makes it depend on the worth of a  tab
              expressed  in  spaces.   Issue an error when the option is given
              twice.

Beyond that, we should agree upon a common indentation setting (number
of columns, and whether to use tabs or spaces). As Python determines
nesting based upon indentation, this isn't just a stylistic issue.

--
Glynn Clements <[hidden email]>

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Daniel Calvelo

Re: Using Python -t ?

Reply Threaded More More options
Print post
Permalink
My vote for 4-space indentation, as this is emacs python-mode default.

Daniel.

On 3/19/07, Glynn Clements <[hidden email]> wrote:

>
> As some people seem to have trouble with indentation, I'd like to
> suggest that the wxgrass script should be changed to use -t, or even
> -t -t:
>
>        -t     Issue  a  warning  when  a source file mixes tabs and spaces for
>               indentation in a way that makes it depend on the worth of a  tab
>               expressed  in  spaces.   Issue an error when the option is given
>               twice.
>
> Beyond that, we should agree upon a common indentation setting (number
> of columns, and whether to use tabs or spaces). As Python determines
> nesting based upon indentation, this isn't just a stylistic issue.
>
> --
> Glynn Clements <[hidden email]>
>
> _______________________________________________
> grassgui mailing list
> [hidden email]
> http://grass.itc.it/mailman/listinfo/grassgui
>


--
-- Daniel Calvelo Aros

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Jachym Cepicky

Re: Using Python -t ?

Reply Threaded More More options
Print post
Permalink
I do not have clear opinion to this. Till now, I was using 4 letters.
Grass default should be 8. It is truth, that 4 letters sound
reasonable, because you lost only half of the space in the line, which
you wold loose, if the indentation would be set to 8

class MyClass:
    def MyFunction():
        if 1:
            #my condition
            while 1:
                #my loop

class MyClass:
        def MyFunction():
                if 1:
                        #my condition
                        while 1:
                                #my loop

We should IMHO set  one-line definiton for vim and emacs to each
python file, which would tell them, how the indentation is set.

for vim, this would be
## vim:ts=4:et:sts=4:sw=4:ai:

jachym
2007/3/20, Daniel Calvelo <[hidden email]>:

> My vote for 4-space indentation, as this is emacs python-mode default.
>
> Daniel.
>
> On 3/19/07, Glynn Clements <[hidden email]> wrote:
> >
> > As some people seem to have trouble with indentation, I'd like to
> > suggest that the wxgrass script should be changed to use -t, or even
> > -t -t:
> >
> >        -t     Issue  a  warning  when  a source file mixes tabs and spaces for
> >               indentation in a way that makes it depend on the worth of a  tab
> >               expressed  in  spaces.   Issue an error when the option is given
> >               twice.
> >
> > Beyond that, we should agree upon a common indentation setting (number
> > of columns, and whether to use tabs or spaces). As Python determines
> > nesting based upon indentation, this isn't just a stylistic issue.
> >
> > --
> > Glynn Clements <[hidden email]>
> >
> > _______________________________________________
> > grassgui mailing list
> > [hidden email]
> > http://grass.itc.it/mailman/listinfo/grassgui
> >
>
>
> --
> -- Daniel Calvelo Aros
>
> _______________________________________________
> grassgui mailing list
> [hidden email]
> http://grass.itc.it/mailman/listinfo/grassgui
>


--
Jachym Cepicky
e-mail: jachym.cepicky gmail com
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Glynn Clements

Re: Using Python -t ?

Reply Threaded More More options
Print post
Permalink

Jachym Cepicky wrote:

> I do not have clear opinion to this. Till now, I was using 4 letters.
> Grass default should be 8. It is truth, that 4 letters sound
> reasonable, because you lost only half of the space in the line, which
> you wold loose, if the indentation would be set to 8

Don't confuse the indentation step with the width of a tab.

Indenting in multiples of 4 columns is reasonable, but that doesn't
change the fact that tab stops are every 8 columns; this is hard-coded
into Python:

        http://docs.python.org/ref/indentation.html

        First, tabs are replaced (from left to right) by one to eight
        spaces such that the total number of characters up to and
        including the replacement is a multiple of eight (this is
        intended to be the same rule as used by Unix). The total
        number of spaces preceding the first non-blank character then
        determines the line's indentation. Indentation cannot be split
        over multiple physical lines using backslashes; the whitespace
        up to the first backslash determines the indentation.

If you only ever use tabs for indentation, then it doesn't really
matter what your editor thinks the width of a tab is. But if you use a
mixture of spaces and tabs, you have to bear in mind that Python will
treat a tab as 8 spaces.

> class MyClass:
>     def MyFunction():
>         if 1:
>             #my condition
>             while 1:
>                 #my loop
>
> class MyClass:
>         def MyFunction():
>                 if 1:
>                         #my condition
>                         while 1:
>                                 #my loop
>
> We should IMHO set  one-line definiton for vim and emacs to each
> python file, which would tell them, how the indentation is set.
>
> for vim, this would be
> ## vim:ts=4:et:sts=4:sw=4:ai:

The ts=4 is bogus; it should be ts=8. sts=4 and sw=4 are okay.

--
Glynn Clements <[hidden email]>

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Brad Douglas

Re: Using Python -t ?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Daniel Calvelo
This would also be in keeping with GRASS C formatting guidelines.  The
closer we can keep the "look" between them, the better the readability.

Once the Python code matures, it would be ideal that someone write up a
SUBMITTING_PYTHON document before it gets committed back to the main
tree for production.

On Mon, 2007-03-19 at 22:31 -0500, Daniel Calvelo wrote:

> My vote for 4-space indentation, as this is emacs python-mode default.
>
> Daniel.
>
> On 3/19/07, Glynn Clements <[hidden email]> wrote:
> >
> > As some people seem to have trouble with indentation, I'd like to
> > suggest that the wxgrass script should be changed to use -t, or even
> > -t -t:
> >
> >        -t     Issue  a  warning  when  a source file mixes tabs and spaces for
> >               indentation in a way that makes it depend on the worth of a  tab
> >               expressed  in  spaces.   Issue an error when the option is given
> >               twice.
> >
> > Beyond that, we should agree upon a common indentation setting (number
> > of columns, and whether to use tabs or spaces). As Python determines
> > nesting based upon indentation, this isn't just a stylistic issue.


--
Brad Douglas <rez touchofmadness com>                    KB8UYR/6
Address: 37.493,-121.924 / WGS84    National Map Corps #TNMC-3785

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui