2 ms·
The indentation is always syntactically correct, but good luck ensuring it's semantically correct.
by bobbylarrybobby 3y ago
The indentation is always syntactically correct, but good luck ensuring it's semantically correct.
- xigoi 3y agoWhy would that be any more difficult than in a brace-based language?
- bobbylarrybobby 3y agoBecause braces delimit entire blocks of code, whereas leading whitespace only delimits a single line of code. It is very easy to stick your cursor between two braces and start typing or paste the clipboard. It is easy to see exactly which depth the added content will exist in. If you'd like a little breathing room, you can put some empty lines between the braces and insert there. Either way, once you (auto)format it'll be fine. But if whitespace is significant, it's not enough to place your cursor in the spot where the content — the whole block — belongs because there is no one spot where the content belongs. Rather, each line of the content you wish to insert must be placed individually. When pasting a block, placing the cursor at the correct spot before the paste is no guarantee that all of the content will be indented correctly; you can only guarantee that the first line is correct (and even then, doing so might require taking into account any leading whitespace of the copied content). Subsequent lines might need to be adjusted to retain the same relative indentation relative to the first line — or not! It depends on your particular scenario. But with braces, there really is no “it depends”. Place cursor, put text. It just works.