Actual drawbacks to omitting semi-colons? [slightly OT]

5,446 views
Skip to first unread message

Sami Samhuri

unread,
Oct 5, 2010, 6:12:17 PM10/5/10
to nodejs
(Kind of off-topic but I respect the opinions in this group. I'll take
it elsewhere if nobody wants to discuss this sort of thing here.)

A lot of people have been talking about ASI (Automatic Semicolon
Insertion) recently, mostly saying that we better understand how the
compiler performs ASI, and that we better insert them anyway.

I'm not going to pretend that I understand JavaScript nearly as well
as Peter van der Zee but I did get a decent score on his "scary" ASI
quiz (high 30s, ninja). http://asi.qfox.nl/

The argument seems to be that we should all include semi-colons
because ASI is evil. What I don't understand is how including semi-
colons saves us from ASI - which compilers perform regardless of
whether we plan to use it or not. To me it looks like the real worry
is Random Newline Insertion (RNI, natch) as exhibited by the ASI quiz.
Unlike ASI which we have to live with, we all have a choice not to
format our code in stupid ways, e.g. using RNI. Including semi-colons
doesn't even save us from the oft-cited "return\n{" mistake.

Am I missing something or is this stuff about the ASI monster just
FUD? I don't use semi-colons right now but I wonder if I'm setting
myself up for problems in the future. People smarter than myself seem
to prefer semi-colons which makes me wonder if I'm doing something
stupid.

-s

Isaac Schlueter

unread,
Oct 5, 2010, 6:33:39 PM10/5/10
to nod...@googlegroups.com
Yes, it's all FUD. In my own code, I don't use semicolons except in a
few specific instances, and then as a prefix or separator. They're
actually not terminators in the JavaScript language, and I think it's
silly to treat them as such. In fact, I'd go so far as to say that my
style is *less* error-prone, because forgotten semicolons are so much
more immediately apparent (since they come at the start of the lines
where they are relevant.)

http://github.com/isaacs/npm/blob/master/doc/coding-style.md

Likewise, I think it's silly to wear pants when it's warm. Everyone
knows it's more comfortable not to, and it's only a silly social
custom that entraps us in these tight pieces of cloth all day long.
In my own house, I'm often pantsless. But when visiting a friend's
house, I put on pants, because that's the custom, and that's how they
like it. (Unless they happen to also be ok with being pantsless, and
then it's an underpants party.)

The point is, I don't put semicolons in npm code, but I do put them in
node code. Because Ryan Dahl wears pants, and node is his house.

In your own house, you get to decide the styles and customs. But be
aware that it might have an effect on who feels comfortable at your
parties.

--i

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>

Ben Noordhuis

unread,
Oct 5, 2010, 6:37:46 PM10/5/10
to nod...@googlegroups.com

jashkenas

unread,
Oct 5, 2010, 11:30:58 PM10/5/10
to nodejs
The scorching newline slashed at my eyelashes and stabbed at my
stinging eyes. That's when everything began to reel. The code carried
up a thick, firey breath. It seemed to me as if the runtime split open
from one end to the other to rain down fire. My whole being tensed and
I squeezed my hand around the semicolon. It gave; I felt the smooth
underside, and there, in that noise, sharp and deafening at the same
time, is where it all started.

I shook off the timeouts. I knew that I had shattered the harmony of
the runtime, the exceptional silence of a GC pause where I'd been
happy. Then I fired four more times at the motionless newline where
the semicolons lodged without leaving a trace. And it was like
knocking four quick times on the door of unhappiness...

mscdex

unread,
Oct 5, 2010, 11:34:47 PM10/5/10
to nodejs
Is this from your upcoming novel? ;-)

Joshua Kehn

unread,
Oct 5, 2010, 11:36:35 PM10/5/10
to nod...@googlegroups.com

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>


Reminds me of using regex to parse HTML...

Regards,

-Josh
____________________________________
Joshua Kehn | Josh...@gmail.com
http://joshuakehn.com

kowsik

unread,
Oct 5, 2010, 11:48:40 PM10/5/10
to nod...@googlegroups.com

Floby

unread,
Oct 6, 2010, 3:05:17 AM10/6/10
to nodejs
Same as Isaac, but I wear pants at home.
> > quiz (high 30s, ninja).http://asi.qfox.nl/

Mihai Călin Bazon

unread,
Oct 6, 2010, 3:22:34 AM10/6/10
to nod...@googlegroups.com
I started writing my 2¢, but it got rather long, so I posted it on my
blog instead: http://mihai.bazon.net/blog/on-automatic-semicolon-insertion

Cheers,
-Mihai

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>

--
Mihai Bazon,
http://mihai.bazon.net/blog

Felix Geisendörfer

unread,
Oct 6, 2010, 4:37:55 AM10/6/10
to nodejs
IMHO the whole semicolon thing does not matter. What does matter
however, is having a community that agrees on some basic coding style,
as that is an important catalyst for open source collaboration.

Right now 93% (of the people on hacker news) prefer semi-colons in
their JS: http://news.ycombinator.com/item?id=1547647

To those who don't, I ask you if semicolons are more important than
the community? Of course you are free to do whatever you want, but if
you are serious about the whole community thing - please show me how
you'll get 93% of the people to change their mind. Otherwise this is
just splitting the community over something as stupid as
semicolons ...

(Of course I'm entirely exaggerating my points here, but hey this is
meant to be a flame-thread, right? : )

--fg

On Oct 6, 12:12 am, Sami Samhuri <sami.samh...@gmail.com> wrote:
> (Kind of off-topic but I respect the opinions in this group. I'll take
> it elsewhere if nobody wants to discuss this sort of thing here.)
>
> A lot of people have been talking about ASI (Automatic Semicolon
> Insertion) recently, mostly saying that we better understand how the
> compiler performs ASI, and that we better insert them anyway.
>
> I'm not going to pretend that I understand JavaScript nearly as well
> as Peter van der Zee but I did get a decent score on his "scary" ASI
> quiz (high 30s, ninja).http://asi.qfox.nl/

Dominic Tarr

unread,
Oct 6, 2010, 6:12:15 AM10/6/10
to nod...@googlegroups.com
crockford explains that ASI works by hitting a compile error, checking if there is a new line, inserting a ; and trying to compile again.

sounds insane to me.

some times it's easiest to just do something all the time, than to decide when to do it or not.

on the other hand, I can't remember to include semi colons all the time, i'm too busy coding.

these are the two choices, always use semicolons, or understand exactly how the compiler does ASI.

people get emotional about things like this, because they can't be rational about it.

Dominic

Jeff

unread,
Oct 6, 2010, 6:36:27 AM10/6/10
to nodejs
The semicolon key on my keyboard is the most visibly worn key on my
keyboard, and I like it that way because I live in society.

It keeps me from standing on the beach, staring at the sea for too
long.

--Jeff

On Oct 5, 11:30 pm, jashkenas <jashke...@gmail.com> wrote:

mgen

unread,
Oct 6, 2010, 7:36:42 AM10/6/10
to nodejs
Crockford is incorrect in it being an error actually. It is a parser.
It doesn't error unless it is extremely poorly built or the syntax is
completely unacceptable. The myth of parser rollback is a terrible lie
if you have ever taken compiler theory past recursive decent parsers.
That being said:

ASI in 2 lines (these steps **do not** occur this is what happens from
a logical standpoint, any decent parser using LL(*) parses would act
just as fast with these as with semicolons (dare i say? probably
faster)):
Does the next line start with a binary operator or this line end with
an operator (keywords that **require** an expression are treated as
operators)? Yes? Attach next line to this line
Is the current line a complete statement? Yes? ASI

Aaron Heckmann

unread,
Oct 6, 2010, 10:36:18 AM10/6/10
to nod...@googlegroups.com
Discussing semi-colons is verboten.

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.




--
Aaron

Sami Samhuri

unread,
Oct 6, 2010, 10:42:32 AM10/6/10
to nodejs
Thanks for the thoughtful and cool-headed comments guys, especially
jashkenas. I think I'll continue to leave them out for now, in my own
code that is. Never any point fighting style when contributing to
someone else's project.

@Isaac: I like the pants analogy. fwiw I like the npm style too, very
similar to mine.

@Ben: Point taken. I guess that newcomers might see some semi-less
code and try omitting them without knowing to prefix lines beginning
with [ and ( with a semi.

@Mihai: js2-mode ftw! I bounce between TextMate and Emacs because
Emacs lacks a good integrated tree-view and find-in-project (or any
project functionality), but at the same time TextMate lacks js2-mode
and general Emacs awesomeness. All editors suck. ;-)

@Felix: Community is the best argument I've seen for using semis.
"Everyone else is doing it" doesn't usually sway me but there's
something to be said for going with the grain in some situations. I'm
learning to pick my battles.

-s

Mikeal Rogers

unread,
Oct 6, 2010, 11:37:26 AM10/6/10
to nod...@googlegroups.com
Noooooooooooooooooooooooooooooooooooooooooooooooooooo


-s

Timothy Caswell

unread,
Oct 6, 2010, 12:28:08 PM10/6/10
to nod...@googlegroups.com
See page 6
http://creationix.com/what-does-node-need-from-us.pdf

:)

On Oct 6, 2010, at 8:37 AM, Mikeal Rogers wrote:

Noooooooooooooooooooooooooooooooooooooooooooooooooooo

Marco Rogers

unread,
Oct 6, 2010, 2:53:19 PM10/6/10
to nodejs
Isaac owes me a beer.


On Oct 6, 12:28 pm, Timothy Caswell <t...@creationix.com> wrote:
> See page 6http://creationix.com/what-does-node-need-from-us.pdf

Sami Samhuri

unread,
Oct 7, 2010, 1:05:44 PM10/7/10
to nodejs
heh, gotcha. looks like it's basically just bikeshedding anyway. the
people advocating semis got me second guessing myself is all.

-s

On Oct 6, 9:28 am, Timothy Caswell <t...@creationix.com> wrote:
> See page 6http://creationix.com/what-does-node-need-from-us.pdf

jashkenas

unread,
Oct 8, 2010, 10:26:24 AM10/8/10
to nodejs
Fogus gets to have the last word on this:

http://blog.fogus.me/2010/08/30/community-standards/

Punto.

Karl Tiedt

unread,
Oct 8, 2010, 10:43:54 AM10/8/10
to nod...@googlegroups.com
In the world of JS where concatenation and minification happens
(browser - I know... not completely node related but it is JS) a
missing semicolon can be very annoying when 2 files (one without a
trailing semicolon) gets the next file appended on the end in such a
way that the parser tries to treat the last line of file A and the
first line of file B as the same line... hence you sometimes see
preceding ; in some Javascript files that are made to be used with
such tools

Just tossing that out there

-Karl Tiedt

Zachary Carter

unread,
Oct 8, 2010, 11:38:23 AM10/8/10
to nod...@googlegroups.com
On Wed, Oct 6, 2010 at 7:36 AM, mgen <genis...@gmail.com> wrote:
Crockford is incorrect in it being an error actually. It is a parser.
It doesn't error unless it is extremely poorly built or the syntax is
completely unacceptable. The myth of parser rollback is a terrible lie
if you have ever taken compiler theory past recursive decent parsers.
That being said:

ASI in 2 lines (these steps **do not** occur this is what happens from
a logical standpoint, any decent parser using LL(*) parses would act
just as fast with these as with semicolons (dare i say? probably
faster)):
Does the next line start with a binary operator or this line end with
an operator (keywords that **require** an expression are treated as
operators)? Yes? Attach next line to this line
Is the current line a complete statement? Yes? ASI

True to an extent – it wasn't too long ago that JavaScriptCore's parser behaved as Crockford described, when they were using Bison.


On Oct 6, 5:12 am, Dominic Tarr <dominic.t...@gmail.com> wrote:
> crockford explains that ASI works by hitting a compile error, checking if
> there is a new line, inserting a ; and trying to compile again.
>
> sounds insane to me.
>
> some times it's easiest to just do something all the time, than to decide
> when to do it or not.
>
> on the other hand, I can't remember to include semi colons all the time, i'm
> too busy coding.
>
> these are the two choices, always use semicolons, or understand exactly how
> the compiler does ASI.
>
> people get emotional about things like this, because they can't be rational
> about it.
>
> Dominic

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.




--
Zach Carter

James Carr

unread,
Oct 8, 2010, 11:42:44 AM10/8/10
to nod...@googlegroups.com
I liked some of the other things on that slide.... couchdb abstraction
frameworks are a dime a dozen in any language. :)

Thanks,
James

Isaac Schlueter

unread,
Oct 8, 2010, 2:44:31 PM10/8/10
to nod...@googlegroups.com
On Fri, Oct 8, 2010 at 07:26, jashkenas <jash...@gmail.com> wrote:
> Fogus gets to have the last word on this:
>
> http://blog.fogus.me/2010/08/30/community-standards/
>
> Punto.

Last word? Hardly.

Jeremy, you of all people should be able to appreciate the artistic
satisfaction in coding.

Some programs are community centers, and you want to entice people to
come inside.
Some programs are factories, and you want to make sure the workers
don't hurt themselves.
Some programs are shops, and you want people to visit, but only a few
go in the back.

And then some programs are art, and while you might hope that some
people find them beautiful or perhaps even useful, and contributions
may be accepted and feedback always welcome, the real purpose is just
to hang it in your house and let it bring you joy.

There is not just one kind of thing in this world.

--i

jashkenas

unread,
Oct 8, 2010, 4:07:41 PM10/8/10
to nodejs
Ack -- a personal appeal! I concede the point. Well argued, Isaac ...
wherever the kids are sticking their semicolons these days, it's no
business of the Thought Police.

If we had a Codestitution in this country, freedom of expression would
be the First Amendment.


On Oct 8, 2:44 pm, Isaac Schlueter <i...@izs.me> wrote:

Mark S. Miller

unread,
Oct 8, 2010, 8:24:59 PM10/8/10
to nod...@googlegroups.com
Isaac, Thanks for the thought, this is really inspiring. I'll be forwarding this around.

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.




--
    Cheers,
    --MarkM

Sean

unread,
Oct 9, 2010, 1:07:55 AM10/9/10
to nod...@googlegroups.com
If this is art , it's most certainly the art minutiae. Write what is readable and save expression for mediums with better resolution. 

Best
sean
Reply all
Reply to author
Forward
0 new messages