Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Do people really think significant indentation is a good idea?

Edit: A lot of people seem to be accidentally clicking the downvote icon.



It works fine in Python. It's nice because the visual indentation lines up with how the interpreter actually reads the code. You don't end up in a situation like this contrived example:

  if (something == somethingElse)
    doSomething();
    --counter; // added afterwards
when whitespace has actual meaning.

Your editor adds the whitespace to match the current scope, so you don't have to type it manually.

What's your issue with significant whitespace?


I don't mind it that much for programming languages like Python. The one annoyance I have is related to editor tooling: In languages that use braces to denote blocks, I can paste a block of code wherever and have my editor autoformat it to the correct indentation level, while in Python I have to be more deliberate with increasing or decreasing the indentation of a pasted snippet, and sometimes I'll make a mistake in the process that isn't caught until later.

I dislike significant indentation for configuration because the nesting tends to get deeper than for programming languages and it can be harder to see what's going on.


> You don't end up in a situation like this contrived example:

Modern languages repair this with mandatory block braces: {C style} (Rust, Go, Swift...) or Modula/Ada style (if x then foo else bar end). C style is easier for editors.

> What's your issue with significant whitespace?

1. Many cases when leading whitespace is still spoiled, including editors (which use can't be avoided due to corporate tool limiting), web formatters, etc. Last decade spreading of mobile-aware tools made this worse.

2. With grouping by indentation, it's hard to determine block start if multiple blocks are ended at the same line, like:

    a:
        b
        c
        d:
            e
            f
    p
and let's imagine the most nested block occupies 2-3 screens (not rare for configs or code, even if it is against good coding rules). You have no means to decide what block start is to be matched when you ask editor to find match.

I code in Python continuously since 2004 and I deem grouping by indentation is bad idea. Not fatally bad, of course, but with explicit grouping it would be a bit better.


I love Coffescript, Sass and Pug for exactly this reason. Just my opinion, though.


Why not? I'm not a Python developer, but bad indentation is considered a faux pas in most production codebases and is already enforced by linters, so I don't really see the issue with enforcing it at the language level.


Apparently. It’s my single biggest pain point with Python, but apparently a lot of people think it’s a good idea.


I'd rather cringe a bit at it than fight on editor style configuration in reviews


I don’t have strong opinions about it


Yes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: