3 ms·
In Python it's especially scary to have some resource management at the end of a block. I have made bugs so many times when after refactoring I screwed up the i
by eatonphil 5y ago
In Python it's especially scary to have some resource management at the end of a block. I have made bugs so many times when after refactoring I screwed up the indentation and the resource management at the end no longer happened in the right way.
The pragmatic approach I've taken to deal with this is make heavier use of custom context managers so creation and cleanup code must stay together.
But I'm also getting tired of whitespace sensitive languages.
- VBprogrammer 5y agoIt's funny, I've been a professional python dev for 8 years or so and I can't remember a single instance of whitespace having caused a bug. The closest I can think of is: if something: ...handle something.. elif something_else: ...handle something else.. if other_thing: ...handle other thing... elif yet_another_thing: ...handle yet another thing... else: ...for everything else... If I had a frustration with python it would be the prevalence of "who needs types when we have dicts". This situation has been somewhat improved by dataclasses but lots of our code predates them by many years.
- marcosdumay 5y agoPython whitespace bites me every once in a while. But this does not generalize to other languages, in particular, I prefer writing Haskell with whitespace sensitivity¹ and I don't remember it ever being a problem. 1 - Last time I asked "who doesn't" on the internet, I found somebody who doesn't. But it's by far the most popular option.
- eatonphil 5y agoTrue. Languages with static type checking probably have this easier because you'll have some warnings about differences in scopes or unused variables.
- marcosdumay 5y agoIt's not that. The whitespace works differently between those languages. The Python syntax has limitations that aren't on the Haskell one. But also, Haskell tends to place the kind of things the GP is talking about on the beginning of your expression (because of the "reverse" order on function composition), while Python tends to place them at the end of a block.
- elcritch 5y agoSimilar benefit in Nim where types help catch stray indent issues. Plus proper scoping of automatic variables in ‘for’ loops helps too.