Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Horne

    #16
    Re: Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

    On Wed, 22 Oct 2003 16:16:15 -0700, Erik Max Francis <max@alcyone.co m>
    wrote:
    [color=blue]
    >Christian Seberino wrote:
    >[color=green]
    >> I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
    >> WITH 8 SPACE IDENTS!!!![/color]
    >
    >You don't really think a style guide is going to stop you from doing
    >that, do you?[/color]

    Exactly.

    My advice is basically do what suits you. Just do it consistently.

    Personally, I prefer two space indents. I'm just too lazy to type any
    more if I can avoid it. But when editing existing code, in any
    language, I just go with what's already there - as long as there is
    some consistent indentation rule evident, anyway.


    Are there any tools which can intelligently redo the indentation in a
    Python source file? Preferably respecting other formatting conventions
    where practical, though of course I accept that no program could
    replace a programmer with an eye for readability in this respect.


    --
    Steve Horne

    steve at ninereeds dot fsnet dot co dot uk

    Comment

    • Dave Kuhlman

      #17
      Re: Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

      Stephen Horne wrote:

      [snip][color=blue]
      >
      > Are there any tools which can intelligently redo the indentation
      > in a Python source file? Preferably respecting other formatting
      > conventions where practical, though of course I accept that no
      > program could replace a programmer with an eye for readability in
      > this respect.[/color]

      If you are on Linux/UNIX or have access to the cygwin tools on MS
      Windows, then try:

      unexpand -4 orig.py > tmp.py
      expand -2 tmp.py > dest.py

      to convert from 4-space indents to 2-space indents, and

      unexpand -2 orig.py > tmp.py
      expand -4 tmp.py > dest.py

      to convert from 2-space indents to 4-space indents.

      But, it does seem like a lot of trouble to go through just so that
      people will look at your code and say "Eewh! Why didn't s/he read
      the style guide?" Or maybe they will smirk and say, "I'll bet s/he
      uses an editor in which the Tab key doesn't work, ... something
      like Notepad on MS Windows. I pity the fool."

      Also, if you have the Python source distribution, look at
      Tools/scripts/untabify.py. Also, in the string module (in the
      standard library) and the string data type, look at the
      expandtabs() method.

      Except, I don't know what these do with tabs in quoted strings.
      The default behavior of unexpand is to convert only
      characters at the beginning of each line. With expand, use the -i
      option to convert only initial tabs.

      Next, ask yourself the following questions: Why is there no
      Tools/scripts/tabify.py? And, why is there no string.unexpand tabs()
      method? Could there be a conspiracy to take away your right to
      use tabs?

      Dave

      --
      Dave Kuhlman

      dkuhlman@rexx.c om

      Comment

      • Erik Max Francis

        #18
        Re: Why Python style guide (PEP-8) says 4 space indents instead of 8space??? 8 space indents ever ok??

        Dave Kuhlman wrote:
        [color=blue]
        > If you are on Linux/UNIX or have access to the cygwin tools on MS
        > Windows, then try:
        >
        > unexpand -4 orig.py > tmp.py
        > expand -2 tmp.py > dest.py
        >
        > to convert from 4-space indents to 2-space indents, and
        >
        > unexpand -2 orig.py > tmp.py
        > expand -4 tmp.py > dest.py
        >
        > to convert from 2-space indents to 4-space indents.[/color]

        Blasphemy! Use a pipe and avoid the need for the temporary file
        altogether:

        unexpand -4 orig.py | expand -2 > dest.py

        etc.

        --
        Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
        __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
        / \ To endure what is unendurable is true endurance.
        \__/ (a Japanese proverb)

        Comment

        • Steve Williams

          #19
          Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok??

          Stephen Horne wrote:
          [snip]
          [color=blue]
          > Are there any tools which can intelligently redo the indentation in a
          > Python source file? Preferably respecting other formatting conventions
          > where practical, though of course I accept that no program could
          > replace a programmer with an eye for readability in this respect.
          >
          >[/color]
          ..../Python.../Tools/Scripts/reindent.py

          Comment

          • Harry George

            #20
            Re: Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

            Stephen Horne <steve@ninereed s.fsnet.co.uk> writes:
            [color=blue]
            > On Wed, 22 Oct 2003 16:16:15 -0700, Erik Max Francis <max@alcyone.co m>
            > wrote:
            >[color=green]
            > >Christian Seberino wrote:
            > >[color=darkred]
            > >> I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
            > >> WITH 8 SPACE IDENTS!!!![/color]
            > >
            > >You don't really think a style guide is going to stop you from doing
            > >that, do you?[/color]
            >
            > Exactly.
            >
            > My advice is basically do what suits you. Just do it consistently.
            >
            > Personally, I prefer two space indents. I'm just too lazy to type any
            > more if I can avoid it. But when editing existing code, in any
            > language, I just go with what's already there - as long as there is
            > some consistent indentation rule evident, anyway.
            >[/color]

            If you never work with others, never edit code from others, and never
            offer code to the OSS world, then I suppose you can do your own indent
            rules. But for those of us in the connected world (and esp. those
            doing XP), playing by the 4-char rule is crucial.

            So the question is: How can you do the correct indents everytime,
            without having to manually count them out? You should be using an
            editor which understands python indents (e.g., emacs with
            python-model.el). Even vi and nedit can be set up to understand
            4-char indents.

            [color=blue]
            >
            > Are there any tools which can intelligently redo the indentation in a
            > Python source file? Preferably respecting other formatting conventions
            > where practical, though of course I accept that no program could
            > replace a programmer with an eye for readability in this respect.
            >[/color]

            [color=blue]
            >
            > --
            > Steve Horne
            >
            > steve at ninereeds dot fsnet dot co dot uk[/color]

            --
            harry.g.george@ boeing.com
            6-6M31 Knowledge Management
            Phone: (425) 342-5601

            Comment

            • Stephen Horne

              #21
              Re: Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

              On Mon, 27 Oct 2003 08:36:04 GMT, Harry George
              <harry.g.george @boeing.com> wrote:
              [color=blue]
              >If you never work with others, never edit code from others, and never
              >offer code to the OSS world, then I suppose you can do your own indent
              >rules.[/color]

              That is emphatically *not* my situation. OK, I've made no significant
              contribution to the open source world (yet) but as a professional
              programmer, working with code that was produced by someone else (and
              usually maintained by a number of people), and writing code to be read
              by someone else is just a basic fact of everyday life.

              My experience is that the size of indent really doesn't make much
              difference as long as it is consistent in each file - you get roughly
              the same number of complaints no matter what length you choose.

              At work, there isn't really a set rule that I'm aware of. Most people,
              when creating a new file, tend to go with either two or four space
              indents, though there are a couple of eight-spacers too, but it really
              isn't a big thing. It doesn't create unreadable chaos, it just means
              some files have wider indents than others.

              And yes, any half-decent editor can be set up to indent properly to
              any width. Mine are set up to use two space indents. But because I
              also regularly end up using new editors (which I've not yet figured
              out how to set up correctly), or simple editors (sometimes notepad
              does the job simply because it is there) or editors set to someone
              elses preferences, or files which use indent levels different to my
              preferences, my habit is to avoid the tab key altogether and just use
              the space key. That way, if I forget that a particular editor has not
              yet been set up to use spaces instead of tabs, I don't get a file
              using mixed tabs and spaces for instance.


              --
              Steve Horne

              steve at ninereeds dot fsnet dot co dot uk

              Comment

              • Harry George

                #22
                Re: Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

                Stephen Horne <steve@ninereed s.fsnet.co.uk> writes:
                [color=blue]
                > On Mon, 27 Oct 2003 08:36:04 GMT, Harry George
                > <harry.g.george @boeing.com> wrote:
                >[color=green]
                > >If you never work with others, never edit code from others, and never
                > >offer code to the OSS world, then I suppose you can do your own indent
                > >rules.[/color]
                >
                > That is emphatically *not* my situation. OK, I've made no significant
                > contribution to the open source world (yet) but as a professional
                > programmer, working with code that was produced by someone else (and
                > usually maintained by a number of people), and writing code to be read
                > by someone else is just a basic fact of everyday life.
                >
                > My experience is that the size of indent really doesn't make much
                > difference as long as it is consistent in each file - you get roughly
                > the same number of complaints no matter what length you choose.
                >
                > At work, there isn't really a set rule that I'm aware of. Most people,
                > when creating a new file, tend to go with either two or four space
                > indents, though there are a couple of eight-spacers too, but it really
                > isn't a big thing. It doesn't create unreadable chaos, it just means
                > some files have wider indents than others.
                >
                > And yes, any half-decent editor can be set up to indent properly to
                > any width. Mine are set up to use two space indents. But because I
                > also regularly end up using new editors (which I've not yet figured
                > out how to set up correctly), or simple editors (sometimes notepad
                > does the job simply because it is there) or editors set to someone
                > elses preferences, or files which use indent levels different to my
                > preferences, my habit is to avoid the tab key altogether and just use
                > the space key. That way, if I forget that a particular editor has not
                > yet been set up to use spaces instead of tabs, I don't get a file
                > using mixed tabs and spaces for instance.
                >[/color]

                You can get away with file-by-file decisions in some languages, but
                not python. As you refactor code among files, and as you do Extreme
                Programming with someone using a different editor, you will kill
                productivity if you are fussing with indents. Go with the guidleines
                and that pain from "accidental complexity" (Brooks term) disappears.
                [color=blue]
                >
                > --
                > Steve Horne
                >
                > steve at ninereeds dot fsnet dot co dot uk[/color]

                --
                harry.g.george@ boeing.com
                6-6M31 Knowledge Management
                Phone: (425) 342-5601

                Comment

                Working...