[OpenLayers-Dev] Semicolons

John Cole john.cole at uai.com
Fri Aug 31 11:18:40 EDT 2007


To add a different opinion, I always use the semicolons.  Why?  To avoid
side effects and avoid ambiguity.  With large projects, we have run into the
situation where a dangling line creates syntactically legal, but logically
wrong code.  And it can be confusing trying to understand why removing (or
adding) a blank line can change how a program operates.

>From the O'reilly JS book:

return
true

Is interpreted as 

return;
true;

When you really meant "return true;"

You can also find weird assignments when someone doesn’t remove a '+' at the
end of a concatenation that would be easier to see if the ';' were always at
the end of the line.

Remember, JS is actually putting the ';' in, it's just trying to figure out
where they go.  It's not that they are not needed; it's a matter of who puts
them in.

"Omitting semicolons is not a good programming practice; you should get in
the habit of using them." --JavaScript, The Definitive Guide, O'Reilly, 4th
Edition

John



-----Original Message-----
From: dev-bounces at openlayers.org [mailto:dev-bounces at openlayers.org] On
Behalf Of Erik Uzureau
Sent: Friday, August 31, 2007 9:51 AM
To: Paul Spencer
Cc: dev at openlayers
Subject: Re: [OpenLayers-Dev] Semicolons

Excellent!

Thanks Paul and Jeff for your quick and insightful responses. I agree
with this approach and will go back and remove those extra ;'s I've
just added. :-)

Erik

On 8/31/07, Paul Spencer <pspencer at dmsolutions.ca> wrote:
> Erik,
>
> I am in favour of a coding style that is syntatically (?) correct
> while requiring the minimum amount of typing.
>
> I believe that using this style:
>
> var foo = function() {};
>
> does require the semi-colon at the end of the statement while:
>
> function foo() {}
>
> doesn't.  I have tested this with jslint and it reports a warning if
> the semi-colon is missing in the first case and not in the second
> case.  An extra semi-colon does not cause a syntax warning either.
>
> As you know, javascript allows some laxity with semi-colons and the
> only time it really bites you is when you want to compress stuff, so
> I'm not really strongly opinionated if this is for test cases that
> are unlikely to be compressed.  However, as a matter of habit, I
> believe that we should use semi-colons in the first style of coding
> and not in the second because the encourages an understanding of why
> the semi-colons are required (or not) which means we will understand
> the language a little better.
>
> Cheers
>
> Paul
>
>
> On 31-Aug-07, at 10:25 AM, Erik Uzureau wrote:
>
> > In a bout of friday afternoon lunacy, I began adding semicolons to the
> > end of the function declarations in the tests files.
> >
> > The original impetus for this was that I noticed that doing so reduced
> > the number of errors reported by the JSEclipse plugin that I use for
> > my JS development work. Certainly neither an urgent nor universal
> > change, but I need to spin some brain cycles.
> >
> > Someone else has brought it to my attention that s/he is *not* in
> > favor of that style....
> >
> > I prefer:
> >
> > function foo() {};
> > and
> > var foo = function() {};
> >
> > whereas s/he prefers:
> >
> > function foo() {}
> > and
> > var foo = function() {}
> >
> >
> >
> > do others have an opinion on this? the OC in me wants everything to be
> > the same in our code, and I'm more than willing to rollback the
> > changes I've just done if people are in favour of the other way of
> > doing it.
> >
> > Please cast a vote if you have some thoughts.
> >
> > Erik
> > _______________________________________________
> > Dev mailing list
> > Dev at openlayers.org
> > http://openlayers.org/mailman/listinfo/dev
>
> +-----------------------------------------------------------------+
> |Paul Spencer                          pspencer at dmsolutions.ca    |
> +-----------------------------------------------------------------+
> |Chief Technology Officer                                         |
> |DM Solutions Group Inc                http://www.dmsolutions.ca/ |
> +-----------------------------------------------------------------+
>
>
>
>
>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
_______________________________________________
Dev mailing list
Dev at openlayers.org
http://openlayers.org/mailman/listinfo/dev

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.484 / Virus Database: 269.13.1/981 - Release Date: 8/31/2007
6:13 AM
 

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.484 / Virus Database: 269.13.1/981 - Release Date: 8/31/2007
6:13 AM
 
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.



More information about the Dev mailing list