Discussion:
[dart-misc] Please no semicolons anymore
Traktor Toni
2017-02-28 08:32:18 UTC
Permalink
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+***@dartlang.org.
'Lasse R.H. Nielsen' via Dart Misc
2017-02-28 12:21:31 UTC
Permalink
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.'
Post by Traktor Toni
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
--
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.
j***@gmail.com
2017-02-28 14:54:36 UTC
Permalink
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.





On Tue, Feb 28, 2017 at 2:21 PM +0200, "'Lasse R.H. Nielsen' via Dart Misc" <***@dartlang.org> wrote:










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 <***@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+***@dartlang.org.
--
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.
--
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.
Istvan Soos
2017-02-28 16:11:25 UTC
Permalink
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
Post by j***@gmail.com
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.
On Tue, Feb 28, 2017 at 2:21 PM +0200, "'Lasse R.H. Nielsen' via Dart Misc"
Post by j***@gmail.com
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.'
Post by Traktor Toni
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
--
'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
--
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
--
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.
'Bob Nystrom' via Dart Misc
2017-02-28 18:27:20 UTC
Permalink
Post by Istvan Soos
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
--
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.
Danny Tuppeny
2017-02-28 17:25:31 UTC
Permalink
On Tue, 28 Feb 2017 at 12:21 'Lasse R.H. Nielsen' via Dart Misc <
Post by 'Lasse R.H. Nielsen' via Dart Misc
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
<https://github.com/dart-lang/sdk/issues/27034> ;-)) 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! =)
--
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.
Traktor Toni
2017-02-28 17:28:08 UTC
Permalink
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.
Post by Traktor Toni
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+***@dartlang.org.
'Lasse R.H. Nielsen' via Dart Misc
2017-02-28 18:38:14 UTC
Permalink
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 Toni
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.
Post by Traktor Toni
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
--
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.
Loading...