Live data from Hacker News

No Semicolons Needed

terts.dev

31–40 of 92 posts

Re: No Semicolons Needed

#32

> I would love to see a language try to implement a rule where only an indented line is considered part of the previous expression. After python, it seems like every language decided that making parsing depend on indents was a bad idea. A shame, because humans pretty much only go by indents. An example I've frequently run into is where I forget a closing curly brace. The error is reported at the end of the file, and…

The issue is that you find you very often want to break those roles. Python basically has `elif` because `else if` would make each branch nest one level deeper which isn't what one wants, except Python uses exceptions for flow control so you find yourself having to use `except ... try` as an analogue to `else if` but not `excetry` exists to do the same and stop the indentation.

There are many other examples. It exists to give people freedom. Also, while humans only go by intendation it's very hand for text editing and manipulation without requiring special per-language support to move the cursor say to the nearest closing brace and so forth.

Re: No Semicolons Needed

#33

Earlier quoted context omitted.

or Raku

Those are functional languages that generally don't use statements, so it makes sense to leave them out of a discussion about statement separators. If you think more people should use functional languages and so avoid the semicolon problem altogether, you could argue that.

Yet, the author ends with a half-backed clone of the Haskell syntax.

Re: No Semicolons Needed

#34
post #25
post #17

Earlier quoted context omitted.

Scala 3 decided to go with indents.

You are not telling the whole story. You can mix indentation and braces to delimit blocks. It's insane.

I like how Haskell does it. One can do both but not mix, as in either indent or use `{ ... }`.

Re: No Semicolons Needed

#35

This article makes a strong case for every language to use ‘;’ as a statement separator.

Indeed it does, by showing how many different and confusing types of parsing rules are used in languages that don't have statement terminators. Needing a parser clever enough to interpret essentially a 2-d code format seems like unnecessary complexity to me, because at its core a programming language is supposed to be a formal, unambiguous notation. Not that I'm against readability; I think having an unambiguous term…

Lisps aren’t necessarily functional, but don’t need semicolons either.

Re: No Semicolons Needed

#36

It's interesting seeing all of the different ways language designers have approached this problem. I have to say that my takeaway is that this seems like a pretty strong argument for explicit end of statements. There is enough complexity inherent in the code, adding more in order to avoid typing a semicolon doesn't seem like a worthwhile tradeoff. I'm definitely biased by my preferences though, which are that I can a…

Start from the perspective of the user seeing effectively:

> error: expected the character ';' at this exact location

The user wonders, "if the parser is smart enough to tell me this, why do I need to add it at all?"

The answer to that question "it's annoying to write the code to handle this correctly" is thoroughly lazy and boring. "My parser generator requires the grammar to be LR(1)" is even lazier. Human language doesn't fit into restrictive definitions of syntax, why should language for machines?

> Because code is still read more than it is written it just doesn't seem correct to introduce ambiguity like this.

That's why meaningful whitespace is better than semicolons. It forces you to write the ambiguous cases as readable code.

Re: No Semicolons Needed

#37

Earlier quoted context omitted.

or Raku

Those are functional languages that generally don't use statements, so it makes sense to leave them out of a discussion about statement separators. If you think more people should use functional languages and so avoid the semicolon problem altogether, you could argue that.

Functional hardly matters Haskell has plenty of indentation which is by the way interchangeable with `{ ... }`, one can use both at one's own pleasure and it's needed for many things.

Also, famously `do { x ; y ; z }` is just syntactic sugar for `x >> y >> z` in Haskell where `>>` is a normal pure operator.

Re: No Semicolons Needed

#38

Earlier quoted context omitted.

It's not. Your eyes can deceive you by guessing the correct indentation. Indentation should never be used for grammar separation. Explicit characters such as } ] ) are clearer and unambiguous.

Clearer for the computer, but not for the human. Many errors, some severe, have been caused by a human only looking at the indentation and not realizing the braces don't match.

That's just because most languages go by braces and have optional intendation that is just ignored by the compiler.

I'd reckon that in a language where stuff is done by indentation but optional braces exist that are just ignored so many errors would also have been caused by braces being misplaced by the programmer to queue other programmers who thought some scope happened as a consequence but the compiler disagreed due to the indentation, which by the way was caused by tabs and spaces being mixed in the code and it not properly showing up for another programmer with tab with set differently.

Re: No Semicolons Needed

#39
I never actually type semicolons in my JavaScript / TypeScript. In work projects, my IDE adds them for me thanks to the linter. In personal projects, I just leave them out (I don't use a linter, so my IDE does not add them), and I've never had a problem. Not even once.

Semicolon FUD is for the birds.

Re: No Semicolons Needed

#40
post #35

Earlier quoted context omitted.

Indeed it does, by showing how many different and confusing types of parsing rules are used in languages that don't have statement terminators. Needing a parser clever enough to interpret essentially a 2-d code format seems like unnecessary complexity to me, because at its core a programming language is supposed to be a formal, unambiguous notation. Not that I'm against readability; I think having an unambiguous term…

Lisps aren’t necessarily functional, but don’t need semicolons either.

The syntax of languages like Lisp and Forth are so fundamentally different that they don't need an explicit statement separator. You don't have to think about many other things either, or I should say you don't have to think about them in the same way. Consider how much simpler the order of operations is in those languages.
Post reply on HN