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 :)'
Post by Traktor Toni90% 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.
Post by Traktor ToniThere 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
--
Lasse R.H. Nielsen - ***@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
--
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+***@dartlang.org.