6 ms·
The computer is really quite proficient at inferring block structure from indentation, and if you use a modern editor this structure is manipulated rather effor
by seanmcdirmid 12y ago
The computer is really quite proficient at inferring block structure from indentation, and if you use a modern editor this structure is manipulated rather effortlessly.
The main problem with indent oriented languages is that not everyone is or wants to use a modern editor. Then there are LISPers who think braces everywhere are a swell idea.
- marcosdumay 12y agoWhat's effortless is putting begin and end of blocks symbols only where they matter. Haskell is particularly guilty of creating several different indenting possibilities, and does require constant intervention. Python is less bad, but still requires more effort than C for example.
- seanmcdirmid 12y agoYou really have to design your language around it for it to work well. Haskell has a a lot of syntactic craziness in the name of simplicity.
- masklinn 12y agoWhat? Haskell has a base language expressed in terms of braces and semicolons, and a relatively simple set of layout rules defining how the compiler can insert these braces and semicolons automatically.
- seanmcdirmid 12y agoRight. I meant that Haskell has a whole lot of other weird syntax to consider, that make it hard to read compared to Python. It's use of indentation is not one of the problems.
- codygman 12y agoCharitably speaking, that is very confusing considering you responded to: > Haskell is particularly guilty of creating several different indenting possibilities, and does require constant intervention with: > You really have to design your language around it for it to work well. Haskell has a a lot of syntactic craziness in the name of simplicity. Where "it" would seemingly be indentation, implying Haskell wasn't designed around making indentation simple.
- masklinn 12y agoEr… you know Haskell's syntax is defined as braces-and-semicolons right? And the braceless-and-semicolons-free syntax is the addition of a few layout rules[0] for human convenience. [0] https://www.haskell.org/onlinereport/syntax-iso.html#sect9.3 https://www.haskell.org/onlinereport/syntax-iso.html#sect9.3
- sparkie 12y agoThe problem is the addition of "a few layout rules" turns the context-free syntax of the language into a context-sensitive one. For example, if you were to write a parser using just the information from the link you've posted, you can enter a scenario where the same piece of code pasted in two different places in a code base mean two different things. Case in point: putting if _ then _ else on separate lines is fine, but inside a do-notation it causes problems because the layout stage inserts semicolons between the parts, and the production rules listed at the bottom of the page do not include optional semicolons in the "if" alternation. You need to indent the then/else to overcome it. This problem is fixed with a hack[0], which fortunately has no side-effects for the rest of the language, but it just shows that throwing together ad-hoc rules for parsing code, rather than well understood theory like LR parsing, is inviting room for problems. With CFG subsets like LR/LL, every production rule in these grammars is also a valid LR/LL grammar - in other words, it's not only the entire grammar of a language that is context-free, but all the parts are too. An indentation-sensitive language is only context-free when looked at for the entire language grammar, but the individual production rules of are context-sensitive. You can't just copy and paste some code into the syntax without providing this context (by means of manually indenting the code). [0]:https://ghc.haskell.org/trac/haskell-prime/wiki/DoAndIfThenElse https://ghc.haskell.org/trac/haskell-prime/wiki/DoAndIfThenE...
- marcosdumay 12y agoYes, I know that. Currently I'm having a better result using parenthesis instead to completely escaping from the semantic blank lines. It's cleaner than using semicolons everywhere. Anyway, Haskell is a very instructive example about how semantic indentation creates problems.
- geocar 12y ago> The computer is really quite proficient at inferring block structure from indentation, and if you use a modern editor this structure is manipulated rather effortlessly. Nonsense. Try pasting a block of Python into Hacker News and you get something that starts off like this: import os import random def do_something(x): if x: fd = os.open(x) and only gets worse. A language with braces/semicolons has no such problem; it is easier to communicate with others, and the absolute value of being able to communicate with others when starting a new language is exceptional.
- vertex-four 12y ago> A language with braces/semicolons has no such problem; it is easier to communicate with others If someone posts more than two lines of practically any curly-brace language as one line, it's illegible. Yes, you can pull it into an editor and fix it automatically, but it's a huge waste of time that is best fixed by simply posting the code properly in the first place.
- geocar 12y ago> any curly-brace language as one line, it's illegible. You might not be able to read it, but others can, so it is by definition not illegible. "Indention language", on the other hand, has actually lost its meaning and therefore is illegible. > it's a huge waste of time that is best fixed by simply posting the code properly in the first place Helping others is never a waste of time, but telling people thy are too stupid to ask for help correctly is cruel.
- vertex-four 12y ago> Helping others is never a waste of time, but telling people thy are too stupid to ask for help correctly is cruel. Asking others politely to help you help them is not cruel in any way. If you allow a community to become a place where people can ask questions without putting any effort at all in themselves, you end up with all the people who can actually help leaving, and your community being full of people who will only ever put in the bare minimum of effort.
- agumonkey 12y agoThe only thing superior to Sexps is Forth. Mechanical syntax forever.
- deleted 12y ago[deleted]
- brudgers 12y agoA token is a token. PEPpy Python's four spaces are isomorphic to Lisp's left banana and C++'s curly brace. An ASCII <bell> would be just as well with a lexer. White space has significance for humans. The road to the Turing tarpit is paved with human intentions. Describing computation mathematically is a solved problem. Expressing it clearly for and by humans, not so much.