Language Syntax: Brackets vs Begin/End vs Indentation

By Xah Lee. Date: . Last updated: .

Of all characters, there's a unique property of brackets such as ( ) [ ] { }. [see Unicode: Brackets, Quotes «»「」【】《》] Namely, they embed info on matching another char in text. This means, any editor, language, or parser, can trivially extract such info. Lisp uses this to advantage, and from it came widely praised lisp macros. Similar with JSON.

languages that use {begin, end}, such as {Ruby, Pascal}, means there need to be semantic info added to such string, and a lot work for parser or text editor to understand the nesting structure. Also, the nesting structure is less easy to recognize visually than brackets.

languages using indentation for blocks and nesting, such as {Python, Haskell, HAML, YAML, Slim} is non-trivial to parse. It actually requires a dedicated parser to understand the nesting.

Indentation syntax is also complex, prone to invalid syntax, because the nesting info must be embedded in each and every line of a nested structure.

Indentation syntax has another problem, which is most serious: Namely, it mixes semantic and syntactical info. That means, no parser/editor can automatically format your code. The code is hard-formatted in one fixed way, and must always be manually formatted. For a damage due to this, see: Why Python's Lambda is Broken and Can't be Fixed.

See also: [Layout Syntax Considered Troublesome By Yin Wang. At https://yinwang0.wordpress.com/2011/05/08/layout/ , accessed on 2016-01-04 ]

See also: Ruby: Learn Ruby in 1 Hour

If you have a question, put $5 at patreon and message me.