3 ms·
> Somewhat surprisngly, indentation-sensitivity in languages like Python and Haskell had me writing cleaner-looking and more readable code by default. Yeah, I'
by dunham 4y ago
> Somewhat surprisngly, indentation-sensitivity in languages like Python and Haskell had me writing cleaner-looking and more readable code by default.
Yeah, I've gone from hating this, to accepting it (after using Python), to wanting it if I were to design a language (after using Haskell/Purescript/Idris).
> Based on this experience alone, if I were to design a non-S-Expression-based language, it would push me toward indentation-sensitivity.
The catch is that it's a pain to parse. Haskell and Python do token injection. Idris has some manual checks (with lots of holes/exceptions) and explicitly passes around an indentation (in some places). A few others conflate parsing and lexing.
I've settled on having a `(layoutRow, layoutCol)` in the state and requiring `col > layoutCol || row == layoutRow && col == layoutCol`. This lets you setup the off-sides layout and still accept the first token at that column.
- dorfsmay 4y agoI use to not only agree with this sentiment but was an evengelist about it. Then fixing a lot of bugs due to people (including myself) getting indentation wrong when refactoring python got me wondering. Then languages servers convinced me indentation is best left to editors and that the cost of braces, semi-colons, etc... is tiny compared to the huge benefit of knowing with 100% certainty and at zero cognitive cost where a block starts and ends.
- brundolf 4y ago+1, since I discovered and embraced "format on save" in my editor I've been able to stop thinking about indentation almost completely
- dunham 4y agoAs I implied, I find the Haskell-like languages attractive. To the point that I am taking that approach in a toy language. But you are right, the cost of it is pretty high - not just copy/paste, but it's tricky to parse, auto-formatting is harder, LSP support (changing code) is harder, renaming variables and functions is harder, etc. (Haskell-like languages are worse than Python because they don't always start a new indentation level on a new line, so renaming can change the indentation level.) So it's probably not worth it. And I will add, like the sibling commenter, I like the auto-format on save of Go. When writing Go, I'll type whatever, often on one line, and let the formatter take care of making it pretty.
- dorfsmay 4y agoIt's not just golang, it's your tooling assuming the syntax of the language you use allows it. I do "reformat on a hot key" in both Rust and Typescript, and use it constantly, way before I save, it helps me review and confirm my logic makes sense. The other advantage is that it standardizes formatting for a given repo making diffs more relevant. Ironically, I believe Python PEP 8 is what started and normalised the idea of taking formating decisions away from developers.