3 ms·
> it enables you to programatically change/fix indentation, because the supposed levels can be recognized by the level of {}. You only need to fix indentation
by nailer 11y ago
> it enables you to programatically change/fix indentation, because the supposed levels can be recognized by the level of {}.
You only need to fix indentation if it doesn't match the block structure. Which modern languages solve by removing the unnecessary* {} tokens.
* If you can remove it, and it still works, it's unnecessary.
- krapp 11y agoWith significant whitespace, you're not really removing them, you're just replacing them with non-printing equivalents. It's an illusion of elegance created in text editors which don't display tabs and spaces, but still basically the same. Visible syntax versus default-invisible syntax.
- pekk 11y agoIndentation is visible. Conservatively estimated, tens to hundreds of thousands of programmers don't have any real problem with syntax based on indentation.
- DrJokepu 11y ago> If you can remove it, and it still works, it's unnecessary. There are elements in source code whose sole purpose isn't only to express instructions to the computer. Expressing the programmer's intent to future readers of the source is obviously also a frequent goal. Comments. Extra parentheses that are not strictly required due to order-of-operations rules. Various annotations and attributes. I mean, these are not exactly new, revolutionary ideas.
- nailer 11y agoYou're completely right: non essential things are fantastic for expressiveness to other developers. I was talking in the context of things which are unnecessary to the compiler, rather than to people. All the things that you mention exist to help the user: that's what indentation's original purpose was, since parenthesis were obviously not good enough. Having the computer respect the same rules humans use is logical and helps remove the chance for inconsistencies.
- blt 11y ago"Consider a syntax with no redundancy: Any random sequence of characters would then be a valid program. No error messages are even possible. A good syntax needs redundancy in order to diagnose errors and give good error messages." - Walter Bright, creator of D language (http://www.drdobbs.com/architecture-and-design/so-you-want-to-write-your-own-language/240165488 http://www.drdobbs.com/architecture-and-design/so-you-want-t...)
- cwzwarich 11y agoHis argument doesn't really apply to programming languages, because when people talk about syntactic redundancy they are generally talking about redundancy in the context-free (or close to it) surface syntax of the language. But the actual language of acceptable programs depends on the name resolution rules and the type system, which generally can't even be expressed with a context-sensitive grammar. In a language with a minimally redundant surface syntax you would still get an error if you use an unbound variable or call a function with arguments of the wrong type. The redundancy here helps tremendously for generating diagnostics. It's not even clear how you would eliminate it, because even determining redundancy (e.g. does a given type have a unique inhabitant modulo reduction) is undecidable in most practical settings. Beyond that, a lot of the surface-level syntactic redundancy comes from the desire to match convention, e.g. using actual words as keywords and imitating mathematical notation.
- nailer 11y ago> "Consider a syntax with no redundancy: Any random sequence of characters would then be a valid program. Nobody was proposing sending raw instructions to the CPU. Instead, the higher level things, like how we indent blocks, should not be repeated. I believe you already know this.