Will motoko support optional/implicit semicolons?

I know, this is not top priority but really wanna ask: can we get rid of those semicolons? :joy:

Currently semicolons is required everywhere, it’s really a pain in the ass. I shoot in my own foot so many times while writing motoko app (and now I’m excessively adding semi everywhere for precautionary purpose).

Or, if you guys can ship a code formatter, like gofmt, I can live with it. Desperately need one!

cc @rossberg

1 Like

Yeah its really annoying haha. I agree.

I agree that semicolons can be annoying, but I’m afraid the problem is that they usually distinguish two perfectly valid parses, so they’re not just noise. For example,

f(4)
(5)

is already valid code, meaning f(4)(5). Similarly for most other cases. So allowing to omit semicolons would be a breaking change, and one that introduces ambiguity for which it is unclear how to resolve it.

One example how not to do it is JavaScript: its “ASI” (automatic semicolon insertion) rules are a big hack and a reoccurring pain point when trying to extend the language – I don’t remember how many times some nice syntax proposal had to be tossed because it wasn’t backwards-compatible due to ASI. It’s also been the source of some hard-to-spot bugs in apps.

A much cleaner solution is how Haskell does it, but its approach is based on a completely different role for braces and semicolons that won’t work with C/Java-style syntax used for Motoko.

Maybe there’s still a way to introduce an ISWIM-style offside rule, but it’s not obvious.

2 Likes