Live data from Hacker News

No Semicolons Needed

terts.dev

41–50 of 92 posts

Re: No Semicolons Needed

#41

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.

I occasionally run into problems with JS weird parsing rules. My favorite is:

    return
        x 
Which does not return. It returns undefined.

Typescript helps a lot with that. A linter will probably flag it as well. Still, JS went way out of its way to accept just about anything, whether it makes sense or not.

Re: No Semicolons Needed

#43

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

Exactly. I genuinely do not understand how any significant user of python can handle white space delimitation. You cannot copy or paste anything without busywork, your IDE or formatter dare not help you till you resolve the ambiguity.

One day https://github.com/mathialo/bython one day!

Re: No Semicolons Needed

#44

> 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 exist…

I'm very okay with elif though because it makes it clear that the conditional is part of the chained block and not a brand new one.

Re: No Semicolons Needed

#45

Earlier quoted context omitted.

> human only looking at the indentation and not realizing the braces don't match. If it ever gets to that point, a refactor is obligatory. Don't give the human tools to make easy mistakes. Any grammar can be abused, so blame the human for not writing clean code.

Javascript's delimeter soup ((){([]{})}); can become near impossible to parse barebrained, especially when mixed with indents and semicolons. Semicolons are just noise. They're absolutely redundant. Some brackets are necessary, but whitespace/indent languages make it clear there's a lot of redundancy there too. The goal is to minimise errors and cognitive load. The fewer characters the better.

> whitespace/indent languages make it clear there's a lot of redundancy there too.

The only purpose for whitespace indentation is to make the code easier on the eyes. A space shouldn't have an impact in terms of execution, that would be too hazardous. It's too easy to randomly insert a space rather than a character.

Re: No Semicolons Needed

#46

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.

> and not realizing the braces don't match.

Make your IDE highlight the current section or display a hint showing starting bracket. For example, C++ devs do #endif // #if ...

Too many brackets? Refactor - problem solved.

Re: No Semicolons Needed

#47
Perhaps having unary minus (and especially unary plus) is just a bad idea in general; just mandate "0 - expr". To make negative constants work properly, you still have to either special case literals "256", "65536", etc. and ideally check whether they got negated or not, or introduce a special syntax just for them, like "~1" of ML for negative one, or "-1" (which you are not allowed to break with whitespace) of some other language I've forgotten the name of.

While we're at it, probably the unary bitwise complement could go as well? Obviously, "^(0-1)" would suck to write but since 99% of the time bitwise "not" used in expressions/statements like "expr &~ mask..." or "var &= ~mask", I feel like simply having binary "and-not" operator that looks like "&~" or "&^" (Golang) is just better.

Also, a small prize (a "thank you!" from a stranger on the Internet i.e. me) to someone who can propose a good syntax for compound assignment with reversed subtraction:

    x ^= 0-1    # in-place bitwise complement
    x ^= true   # in-place logical negation
    x ?= 0      # in-place integer negation???

Re: No Semicolons Needed

#48

Earlier quoted context omitted.

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 d…

> tabs and spaces being mixed in the code

Python banned this in python3. Problem solved.

Re: No Semicolons Needed

#49

> 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 exist…

> Python basically has `elif` because `else if` would make each branch nest one level deeper which isn't what one wants

There are, of course, other ways to handle this. For instance, "else if :" could've been made legal à la Golang:

    IfStmt = "if" [ SimpleStmt ";" ] Expression Block [ "else" ( IfStmt | Block ) ] .

Re: No Semicolons Needed

#50
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.

Lisp has explicit "statement" terminators (just aren't semicolons)
Post reply on HN