3 ms·
And this is one reason I still don't understand the use of python in large teams! I suppose with very good tests, you might be able to catch something like thi
by yurishimo 2y ago
And this is one reason I still don't understand the use of python in large teams!
I suppose with very good tests, you might be able to catch something like this, but it seems impossible to me how a PR reviewer might catch a "bug" like this and not just assume that it's intentional.
- DemetriousJones 2y agoOne of my biggest gripes with python is the fact that the only way to create a local scope for variables is with functions. I understand if statements not having their own scope for simplicity's sake, but the fact that `with` blocks don't is simply mind-bobbling to me. ``` with open("text.txt", 'w') as f: f.write("hello world") f.write("hello world") # at least the handle was automatically closed so it will give an IO error ```
- DemetriousJones 2y agoSorry for the borked code formatting
- orf 2y agoIt’s actually very useful to have context managers outlive their with blocks. They are not only used for files: One example would be a timing context manager: with Timer() as t: … print(t.runtime) Another example is mocks, where you want to inspect how many times a mock was called and with what arguments, after the mock context manager has finished.
- DemetriousJones 2y agoI know it makes sense in the "scope-less" python philosopy but it still feels weird for me as a scope (ab)user in C++ and has caused me one headache or two in the past
- neongreen 2y agoI learned about the `scoping` package today. Idk if it works exactly as I expect from other langs, though.
- kstrauser 2y agoOTOH I’ve written Python professionally for about 25 years and I truly don’t think I’ve ever seen a bug due to accidental mis-indentation like that.
- lostdog 2y agoWhen I worked in python I made this exact mistake monthly.
- kstrauser 2y agoHow, though? Every code editor I've used supports holding indentation at a certain level until you change it, so if you write: if foo: bar() and hit enter after the "bar()", it would drop you down so that the next thing you type would be under the "b". It's not really different from using curly brackets from the perspective of typing in code.
- lostdog 2y agoCut and pasting code to move it around. Every editor was just slightly jittery about keeping the indentation levels consistent.
- lukaslalinsky 2y agoCompletely agree, this is a common argument ever since Python existed. I've also used it for almost 25 years and these kind of indentation errors just don't happen. I see it the same as forgetting closing brace. Python programming writing C code might forget it initially, but C programmer absolutely will not forget it, it's in their muscle memory. And the same applies for dealing with indentation.