Please no semicolons anymore

589 views
Skip to first unread message

Traktor Toni

unread,
Feb 28, 2017, 3:32:18 AM2/28/17
to Dart Misc
There is no point, it's just "to be familiar" and even at that it kinda fails because javascript doesnt have them but let's not make this a discussion about pros or cons because it's always going to be subjective and I just want to post my subjective opinion: I dont like typing them. 

Lasse R.H. Nielsen

unread,
Feb 28, 2017, 7:21:55 AM2/28/17
to mi...@dartlang.org
Semicolons do require shift-key on some non-US keyboards. That alone makes them annoying.

There is a point to having them, though: It's *simple*.
With mandatory semicolons, there is no discussion about where a statement ends - it ends at the semicolon. Without semicolons, you have a wide variety of options - always end at newline (probably not useful, some statements won't fit on a line), end on a newline if *some conditions* (simple and predictable conditions preferably), or something exceedingly clever.

The JavaScript rules for automatic semicolon insertion are ... less than amazing. It's too hard to figure out whether a semicolon is inserted in some cases. That's why you get things like "semicolon first" style - it tries to work around the problem that the language is too complex for its own good.

Semicolons are *often* redundant, but it's simpler and less error prone to always write them than it is to only write them when you need them - because if you get it wrong, the cases where you do *need* them are exactly the cases where omitting them will still compile and do "something".

So, even if we dislike semicolons, we can't just *remove* them. We need to add something else instead, and that something needs to be simple, predictable, nice to use, and not have pitfalls that users keep hitting.

/L 'Not saying it can't be done.'



On Tue, Feb 28, 2017 at 9:32 AM, Traktor Toni <trust...@gmail.com> wrote:
There is no point, it's just "to be familiar" and even at that it kinda fails because javascript doesnt have them but let's not make this a discussion about pros or cons because it's always going to be subjective and I just want to post my subjective opinion: I dont like typing them. 

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.



--
Lasse R.H. Nielsen - l...@google.com  
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - Denmark - CVR nr. 28 86 69 84

jan.m...@gmail.com

unread,
Feb 28, 2017, 9:54:48 AM2/28/17
to 'Lasse R.H. Nielsen' via Dart Misc

Kotlin has optional semi-colons, if you want more than one statement on a line, only then it is needed. Not sure how they deal with statements spanning multiple lines.

Istvan Soos

unread,
Feb 28, 2017, 11:11:49 AM2/28/17
to General Dart Discussion
Optional semicolon seems to be a good idea, until it hits you really hard.

Last year I needed to track down a weird bug in a node.js service. The
code looked fine, the logs were fine, except for some edge cases.
After a full day of debugging, it was tracked down to a missing
semicolon (line wrapping can be hard). It is not fun debugging it, I
could have spent that day with meaningful work instead.

My personal experience was that ambiguous syntax (e.g. semicolons, or
structures in CoffeeScript) is much harder to read. This becomes more
apparent issue if you are in a larger team.

Cheers,
Istvan

Danny Tuppeny

unread,
Feb 28, 2017, 12:25:46 PM2/28/17
to mi...@dartlang.org
On Tue, 28 Feb 2017 at 12:21 'Lasse R.H. Nielsen' via Dart Misc <mi...@dartlang.org> wrote:
Semicolons do require shift-key on some non-US keyboards. That alone makes them annoying.

Given how often we have to press the shift key (parens, braces, quotes, exlamation marks, dollars, ampersands, pipes and all the camelCase letters) I'm not sure eliminating semicolons is going to make a huge dent here!

I think there are better things to spend time on (non nulls, json, this ;-)) than trying to make a good solution to avoid semicolons. If a dev is typing enough semicolons for this to be significant, I can't help but think there's too much typing and probably not enough thinking going on! =)

Traktor Toni

unread,
Feb 28, 2017, 12:28:09 PM2/28/17
to Dart Misc
90% of the time I write semicolons anyway, I like how they look. You are all right that it makes the code more explicit somehow. 
But sometimes I just hammer some code out really quickly and then it annoys the hell out of you to have to type one out at every line.
Golang doesnt even require semicolons and those guys are *really* particular about their syntax.

Bob Nystrom

unread,
Feb 28, 2017, 1:27:56 PM2/28/17
to General Dart Discussion

On Tue, Feb 28, 2017 at 8:11 AM, Istvan Soos <istva...@gmail.com> wrote:
Last year I needed to track down a weird bug in a node.js service. The
code looked fine, the logs were fine, except for some edge cases.
After a full day of debugging, it was tracked down to a missing
semicolon (line wrapping can be hard).

This is because JavaScript's implicit semicolon rules are batshit insane.

Other languages have non-crazy newline handling rules and don't have these problems. Go, Scala, Lua, Python, Ruby, Kotlin, Swift, etc. In all of those, idiomatic code does not use semicolons and people seem to get by OK. It really says something about JavaScript's semicolon insertion rules that many JavaScript style guides explicitly prohibit relying on them.

– bob

Lasse R.H. Nielsen

unread,
Feb 28, 2017, 1:38:38 PM2/28/17
to mi...@dartlang.org
The Go language uses a semicolon insertion strategy that is something like: If the last token on a line, or before a '}', could be the last token of a statement, insert semicolon.

Kotlin is something like: Parse line-ends as semicolons if a semicolon is allowed by the grammar (basically the grammar doesn't require a semicolon, but a "semicolon or newline"). 

Two different approaches. Kotlin doesn't insert semicolon before a '}', only on newlines, which probably means that their style guide says to always put '}' on a separate line (no "if (test) { braceForImpact() }").

In both cases there are trade-offs: Programs that won't work as you expect because of the inserted semicolon.

Kotlin:

fun main(args: Array<String>) {
    var x = 21
    x = AmazinglyLongNameThatWontFitAnythingElseOnTheLine(x) 
      - x
    println(x)
}

fun AmazinglyLongNameThatWontFitAnythingElseOnTheLine(x: Int) : Int {
    return 2 * x 
}


Of course you wouldn't write something like that. Of course! But maybe ... It just takes one bad day where you forget to put the '-' on the previous line, and you are back to debugging the missing semicolon.

I don't have a good example in Go - they are often saved by them making unused evaluations compile-time errors, so the '-x' above gives you a "main.go:10: -x evaluated but not used" error. It's not a syntax error, though, and I don't think we'd get away with making unused evaluations errors in Dart (especially since we can override 'operator-', so it's hard to see that `-x` doesn't do anything).
You really have to tailor your rules to the language you have, there is no "one size fits all" auto-statement-terminator algorithm. It's plausible that Go has hit the sweet spot for their language, but Dart can't use the same rules because it's a different language.

And as Bob says, JavaScript fails at being predictable enough to be reliable. There are just too many exceptions, and in order to know if a semicolon is inserted, you need to know the grammar well enough to know if the next *token* can continue the statement. That is, you need to know not only the valid syntax of JavaScript expression, but also all the valid prefixes of them. 

I'm sure a solution can be found. The only question is which badness it has to allow, or goodness it has to disallow, in order to avoid ambiguity in parsing. Not getting it right is, arguably, worse than not doing anything.

/L 'still want to do something :)'


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Reply all
Reply to author
Forward
0 new messages