Re: Grouping code by indentation - feature or ******?

From: Carl Banks (invalidemail_at_aerojockey.com)
Date: 03/25/05

  • Next message: Antoon Pardon: "Re: Grouping code by indentation - feature or ******?"
    Date: 25 Mar 2005 06:15:30 -0800
    
    

    Tim Tyler wrote:
    > What do you guys think about Python's grouping of code via
    indentation?
    >
    > Is it good - perhaps because it saves space and eliminates
    keypresses?

    It's good, but this is only a minor reason.

    The reason this is good is because it exactly reflects the way human
    beings mentally group code in their heads. In Python, you can eyeball
    grouping with 100% accuracy (except for one flaw that's being phased
    out). Not so with other languages. In other languages, you have two
    simultaneous ways of grouping code: the way that makes sense to humans
    (indentation), and the way (braces or begin/end). This creates the
    possibility of mismatch, and it puts an extra burden on the programmer
    to make sure computer and human grouping stays synchronized.

    Grouping by indentations also goes a long way to prevent sloppiness.
    No matter how sloppy your style is, you can't slop away the way the way
    program was nested in Python; thus a reader should be able to follow
    the flow of just about any code. I've ended up as the computer expert
    at my engineering firm, so I get (non-Python) code to debug from time
    to time, and I can attest that inconsistent style is the single worst
    thing that everyone does to make code unreadable. Python-like
    indentation would instantly halve that problem.

    The drawbacks are insanely minor. It makes one liners more difficult,
    and can result in transmission difficulties with some stupid programs
    that helpfully strip leading whitespace. (There's another drawback in
    Python that isn't inherent to grouping by indentation, namely the
    possibility of mixing spaces and tabs. This is the flaw that's being
    phased out.)

    > Or is it bad - perhaps because it makes program flow dependent on
    > invisible,

    It doesn't. I suspect Pythonistas will heavily attest to that. But,
    as I said, it does make it virtually impossible for sloppy code to
    mislead you about the flow. Overall, if someone hands you a random
    piece of C code, and a random piece of Python code, you will be more
    likely to easily follow the flow of the Python.

    > and unpronouncable characters - and results in more
    > manual alignment issues by preventing code formatters from managing
    > indentation?

    This is true. Most common complaint is changing the nesting level of a
    block of code. Good editors have ways to cope with this, just as good
    editors have ways to cope with all these superfluous braces in other
    languages.

    > Python is certainly pretty unorthodox in this area.
    >
    > How would you have dealt with the issue of how to group statements?

    Having experienced Python, I can say pretty earnestly that, were I
    designing my own language, there is no other way I would do it.
    Grouping by indentation is a slam dunk for me.

    -- 
    CARL BANKS
    

  • Next message: Antoon Pardon: "Re: Grouping code by indentation - feature or ******?"

    Relevant Pages

    • Re: OT - trivial programming language
      ... |> That makes two votes for Python. ... If you think indentation doesn't matter, join any C, C++ or Java ... keyboard engraved with the label 'Tab' is pressed. ... If you use vim, set the following options. ...
      (Debian-User)
    • Re: Grouping code by indentation - feature or ******?
      ... In Python, you can eyeball ... IMO the flow of a lot of code would be easier to follow if code ... > indentation would instantly halve that problem. ... > designing my own language, there is no other way I would do it. ...
      (comp.lang.python)
    • Re: A decorator syntax not yet mentioned (I think!)
      ... Because to me it doesn't *act* like normal Python. ... except for the few that are based on indentation ... It seems like we both agree that the @pie syntax doesn't ...
      (comp.lang.python)
    • Re: Hows ruby compare to it older brother python
      ... >>to Perl than to Python. ... > as syntax and Ruby doesn't. ... As I said in another post, indentation is the reason I learned ...
      (comp.lang.python)
    • Re: Python indentation
      ... > I am a beginner in Python, and am wondering what is it about the indentation ... > in Python, without which python scripts do not work properly. ... In many languages, such as C or Perl, you can write readable code, but ... but the script is much more readable than the Perl counterpart ...
      (comp.lang.python)