[Javascript] line end character ;

Chris T christ at saeweb.com
Tue Jun 22 12:36:48 CDT 2004


I'm looking at an example of JavaScript 1.5 and here's what is says
regarding semicolons:

=======================
Multiple statements may occur on a single line if each statement is
separated by a semicolon.
=======================

Nowhere does it say that it's bad practice to not use it and I've never
heard that. It's all a matter of preference and consistancy. For example,
what type of naming conventions you use. It's not neccessary to use any one
way, but it's just advised that you stick with whichever method you do gow
ith.

Chris Tifer


----- Original Message ----- 
From: "liorean" <liorean at f2o.org>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Tuesday, June 22, 2004 12:37 PM
Subject: Re: [Javascript] line end character ;


> Mike Dougherty wrote:
> > Should external script files use the line end character ; as a rule?
>
> The don't need it, but as a programmer the recommendation is to never
leave it out.
> In fact, it's considered bad practice to rely on implicit behaviors of any
kind.
>
> > I left it off, now the javascript code cruncher(s) expect to find it
>
> That's because it would be much more job for them to insert semicolons
with 100% specificity and 100% sensitivity both. For instance, this is a
single simple statement, in fact a single call expression:
> ----<>----
> window
>
>  /*comment
>                                    comment*/.
>
>
> alert
>
> (
>
>
> // blah...
>
> "bad code!"
>
>                     )
> ----</>----
> While these are two complex statements, where the single semicolon
terminates neither (it terminates a simple statement that is a part of one
of the complex statements):
> ----<>----
> while(true){break}do break;while(true)
> ----</>----
>
> Now, making a cruncher that handles those cases, and the more complex
cases that may appear, means that you effectively need to write an entire
tokeniser for JavaScript just for that cruncher, something that I don't
think very many are prepared to do. Especially since we have special cases
such as the return statement, where you may not insert a line break between
the return keyword and the return value, unlike most other statements.
>
> > If the right thing to do is end lines with ";" then why isn't it
required?
>
> Because JavaScript is made to appeal to three camps:
>  - Procedural and imperative (Pacal/C/C++/Java) programmers, having a very
similar syntax.
>  - Structured and functional (Scheme/LISP/ML/Haskell/APL/J/K/Python)
programmers, having many features from both paradigms, but in general having
a syntax without the syntactic explicitness of the first group of languages.
>  - HTML coders, that are not really programmers and therefore are helped
by laxer syntax rules. (Remember that JavaScript comes out of the same
company that created the current tagsoup hell in the first place, in a time
when tagsoup was considered to be absolutely optimal.)
>
> Semicolon insertion in itself is not bad. A parser may do it as a feature.
It was a bad feature to make mandatory in the standard, however, a bad
design decision on both the behalf of Netscape and ECMA.
>
> > I don't think developers should be allowed (by the language) to be lazy
> > with regards to syntax, we're lazy enough everywhere else :)
>
> ECMAScript 4 will not make it much easier for you, but you have one very
nice feature in it: strict parsing mode. Have a look at the Mozilla
JavaScript Language resources <http://www.mozilla.org/js/language/> if you
want to see what ECMAScript 4 will look like.
> -- 
> David "liorean" Andersson
>
> ViewStyles, ViewScripts, SwitchStyles and GraphicsInfo bookmarklets:
> <http://liorean.web-graphics.com/>
> Hangouts:
> <http://codingforums.com/> <http://yourmusicforums.com/>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list