Comment by graemep
6 hours ago
I think indentation is more intuitive. Even people using languages that use braces or similar usually use indentation to make code readable. If doing that you end up explaining both ideas (use braces and indent).
6 hours ago
I think indentation is more intuitive. Even people using languages that use braces or similar usually use indentation to make code readable. If doing that you end up explaining both ideas (use braces and indent).
There's an important form/function distinction here, though. Indentation is useful for human readability, but braces function to give unambiguous direction to the compiler or interpreter. I think conflating these two different purposes together is a mistake: you shouldn't risk altering or breaking the logic flow of a program simply by adjusting its visual formatting.
The fact that we use whitespace for layout is precisely why it's a bad idea to assign it semantic value. I'm a fan of both braces and semicolons for that reason.
I think this is probably correct for an experienced programmer but incorrect for someone who is new.
I'm not sure I understand what you mean. How would the friction inherent in conflating layout and semantics together depend on the experience level the programmer? Different programmers might have different ways of dealing with that friction, but I'd think its existence would be a property of the language itself.
1 reply →
I get why people like indentation for this. I don’t think there’s a right or wrong answer and it’s a matter of personal preference.
That said, my preference is curly braces (or whatever) because I’ve found indentation is often a bother. Yes, most of the time you use indentation together with braces, but not every time. There are many occasions where code is clearer without (or with custom) indentation. Furthermore, indentation-based parsing makes experimentation and finding issues more difficult. Sometimes you need to extract a small part of a larger block to bung in a REPL or something and now you’re fighting with stupid errors because of formatting, adding to the frustration.
Regarding intuitiveness, for beginners I have some doubts it makes much of a difference, and if it does I also doubt indentation wins. If you know how to write (which is a prerequisite), you know what parenthesis and quotation marks are, you understand they encapsulate something separate from the rest. Indentation is a different concept.
I get why people blame indentation like this. I don't think it's right or wrong to ignore the tooling that directly addresses minor issues with indentation or matching braces honestly.
That said, my preference is to use the tools built into my editor and available on the CLI or web to assist and fix formatting and syntax. You get instant feedback on incorrect formatting, and I generally find that synthetic scope mistakes (regardless of method) are eliminated.