PEP 8 : Maximum line Length :

Discussion in 'Python' started by Ganesh Pal, May 13, 2014.

  1. Ganesh Pal

    Rustom Mody Guest

    You said this:
    And you answered:
     
    Rustom Mody, May 16, 2014
    #41
    1. Advertisements

  2. Containing *what*? You can't just wave your hands and say "binary". What
    sort of binary file? Perhaps a JPEG file, where red triangles of
    different sizes represent keywords. Variable names can be encoded using a
    pattern of purple dots. Expressions and blocks of code can be formed by
    joining components with lines. Operators by squares of different colours
    (green means +, blue means -, etc.).

    No? Then what?

    Besides, where does the information inside the file come from? You surely
    don't expect people to write the binary data/AST/whatever directly. How
    can the zip file be "definitive" when it is derived from something more
    fundamental?

    Source code is, *by definition*, the definitive version. (It's the
    SOURCE, see?) Zipping the source code just means that the *source* inside
    the zip file is the definitive version, not the compressed binary data.

    The AST is not definitive. Human beings write *text*, which is what the
    source code is. It may be text with an especially restrictive grammar,
    but it's still text. Everything else -- the parse tree, the abstract
    syntax tree, the byte code, the machine code, the compressed text,
    encrypted text, the pixel rendering of the text, ... are derived from the
    code as written by human beings.

    Code is written primarily for human beings. Many programmers, and many
    language designers, don't realise this, which is why so many programs are
    write-only code. Presentation *is important*, and cannot always be
    separated from semantics without hurting the primary audience, the human
    reader. This is what code obfuscators do, deliberately: mangle the
    presentation while keeping the semantics the same. You're inadvertently
    proposing the same thing (albeit to a lesser degree).
     
    Steven D'Aprano, May 16, 2014
    #42
    1. Advertisements

  3. I don't believe anyone has made that claim. You are reading a statement
    about general (typical, average) behaviour, and turning it into an absurd
    statement of a "fundamental" (your word) which applies to every single
    human being on earth.
     
    Steven D'Aprano, May 16, 2014
    #43
  4. http://www.dangermouse.net/esoteric/piet.html

    ChrisA
     
    Chris Angelico, May 16, 2014
    #44
  5. You still haven't answered my biggest objection from earlier. Source
    code contains more information than the AST does; even if you make a
    frAnkenSTein's monster that includes comments, there's still the point
    that whitespace carries information, and that information is
    frequently communicative of the programmer's intent. Any automated
    reformatter destroys that information, and that is, by definition, a
    net loss to the code. How do you propose to fix that? Or if not, will
    you at least acknowledge that the AST cannot perfectly transmit what
    the source code says?

    ChrisA
     
    Chris Angelico, May 16, 2014
    #45
  6. If every bit of your Python text conveys information, obviously, it
    can't be abstracted. I don't believe that to be the case, though. So
    this AST should contain all *actual* information worth conveying and
    strip away irrelevant stuff.

    Examples:

    * Function definition order.

    * Indentation depth.

    * Vertical empty space.


    Of course, I'm not being completely serious about all this stuff because
    the surface coding style questions are among the least relevant problems
    in the code. But at least that kind of arrangement would free us from
    the heated debates concerning the maximum line length etc.

    (BTW, regardless of PEP8, the maximum line length *must* be 79, and the
    maximum function length *must* be whatever can be seen on the screen at
    once.)


    Marko
     
    Marko Rauhamaa, May 16, 2014
    #46
  7. * Logical layout as expressed by whitespace and specific line breaks.

    Compare these two assignment statements:

    area = (base*base + extension*extension
    + annex*annex + (annex-extension)*annex
    + triangle*triangle/2
    + circle*circle*math.PI + sphere*sphere*4*math.PI)

    area = (base*base + extension*extension + annex*annex
    + (annex-extension)*annex + triangle*triangle/2
    + circle*circle*math.PI + sphere*sphere*4*math.PI)

    Both are wrapped to sixty characters, which means they can be indented
    twenty without breaking PEP 8. One of them takes up only three lines,
    the other takes up four. But the first one groups the annex's terms,
    separates out the triangle, groups the circular elements, and
    presumably corresponds accurately to the (mythical) real-world
    geometry that it's implementing. How are you going to cope with this
    distinction? That's real, useful information, which the AST doesn't
    carry.

    (You might argue that each of these lines should have a comment at the
    end of it or above it, which would provide that grouping. But in that
    case, you lose the canonicalization of anything with trailing comments
    or interspersed comments, meaning that you effectively can't reformat
    anything with comments in it.)

    ChrisA
     
    Chris Angelico, May 16, 2014
    #47
  8. Such nuances would be lost, yes. However, the nuances are constantly
    abused and misinterpreted anyway.


    Marko
     
    Marko Rauhamaa, May 16, 2014
    #48
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.