last week i fixed a bug where a mistake in indentation (maybe a cut and paste in a refactor?) caused something to be done once but not the correct number of times (once for every iteration). took a few minutes to figure out where to look, but it took a few minutes more to figure out what was intended and what the bug ultimately was (the disconnect between what you meant and what you did). while this is a small 2 line example, for larger code blocks this is a serious problem.
i'm not advocating for braces, but they have a helping hand in spotting these sorts of bugs.
that said i often dislike it when people dismiss python just on the whitespace complaint alone.
But I've also committed bugs due to putting something on the wrong side of a closing brace.
> Typically, refactoring applies a series of standardised basic micro-refactorings, each of which is (usually) a tiny change in a computer program's source code that either preserves the behaviour of the software, or at least does not modify its conformance to functional requirements. Many development environments provide automated support for performing the mechanical aspects of these basic refactorings.
If you attempt to do computer's work for them, you're going to screw up. I screw up manual refactorings in Java too (e.g. misspelling variable names, misspelling one of the gazillion xml file declarations), and much more than in Python. Don't do manual refactoring.
The real flaw is that the architecture of python makes automated refactoring impossible. This is not due to the indentation sensitivity of Python.
Would be very interested in projects that remove braces from other languages, though!
So, while you can write messy, unindented code, if you run gofmt over it, it'll look like everyone else's code (but probably still messy, because if you can't be bothered to indent your code, why would you be bothered to write clean code?).
I imagine I could train myself to do so, but there is a cost involved.
This is one of the good things about significant indentation: the human and the computer are reading the same signals.
That said, I do sometimes write in Python and I have nothing against the language. This isn't meant to be an attack on Python.
Edit: also, the indentation in the first example is obviously just a means of illustrating that whitespace is non-significant with this project. I don't think they're suggesting code ought to be written without correct indentation.
Does anyone anywhere have a realistic example of Python's indentation system being a hindrance? To me, the complaint always comes across as "I should hypothetically be able to do things that I would never actually do or endorse doing"
And it's not like there's no flexibility for weird corner cases. I mean, all of these things are already legal Python 3:
for i in range(10): print(i)
# although you wouldn't actually do this
a = 3; b = 5; # a,b = 3,5
# and you REALLY wouldn't do this but I couldn't help coopting their example
if foo == "bar": _=(
print("indenation"),
print("doesn't"),
print("matter!")
)Guard statements and low cyclomatic complexity are important in all languages, but doubly so in python.