3 ms·
> to indent some code. Why are you manually indenting code? I don't remember ever doing that in IDEA or VS Code for ~~python,~~ java or ts. Edit: I borked ab
by Mashimo 2y ago
> to indent some code.
Why are you manually indenting code?
I don't remember ever doing that in IDEA or VS Code for ~~python,~~ java or ts.
Edit: I borked about python, my bad.
- rfoo 2y agoFor example, you have if check_something(): wall_of_text = textwrap.dedent(""" this is a multiline string """.strip("\n")) I hope you agree it's ugly. And you want to make it if check_something(): wall_of_text = textwrap.dedent("""\ this is a multiline string """.strip("\n")) But I don't know any formatter which does this automatically. Because the change here not only changes the looking, it changes semantic. The formatter has to understand that after `textwrap.dedent(_.strip("\n"))` the result does not change and that's hard. So formatter just leave it alone. But it's extremely obvious to a human. Or maybe extremely obvious to a LLM too.
- Mashimo 2y agoYeah, string """ blocks I also have to do manually. Though that example never interfered with AI autocomplete in my experience.
- oneeyedpigeon 2y agoIsn't indentation 'non deterministic' in Python? E.g. if I have the following: if (foo): bar() hum() how can anything other than a human decide if that 3rd line should be indented as it is or by one more level?
- saghm 2y agoEven humans have trouble with that sometimes: https://www.blackduck.com/blog/understanding-apple-goto-fail-vulnerability-2.html https://www.blackduck.com/blog/understanding-apple-goto-fail...
- oneeyedpigeon 2y agoAlthough, not in Python of course! :)
- yurishimo 2y agoAnd 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.
- fragmede 2y agoHow does the IDEA/VSCode know when you're done with the if? if foo: bar # Obviously this is indented but_is_this() # supposed to be under the if? how.about(this) #? how.do_you(de) # indent in Python, if not manually?