|
|
|
|
|
by frodowtf
1019 days ago
|
|
> ... it's not intuitive how deep I am within nested scopes The ONLY piece of information that is available to you regardless of how deep you are into a function is INDENTATION. Your curly braces won't help you. Besides that, you should seriously reconsider your coding style if this is an actual problem for you. |
|
...No? It sounds like you write very long, messy code blocks. Consider the following example, I will write a nested loop in 2 languages:
In Python:
Here's something similar in JS: In isolation, while I'm writing this comment, I would say these code blocks are equally easy to parse. In the context of frantically debugging, scurrying around a file, I may (and have!) missed the indentation difference in the Python example.Curly braces allow me to have 3 visual indicators that a block is finished: a visual text object (the brace itself), an extra line separator (the closing brace lives on its own line), and indentation. In Python, I only have one of those things (just indentation). I can have 2 (indentation + line sparation) if I always insert a newline before `print("Outer")`, but empty lines can get deleted and I may forget to include them as I write code. You'd need to configure a linter to guarantee the line separation indicator in a language that delimits scopes by whitespace.