[Javascript] line end character ;

Mark Wonsil wonsil at 4m-ent.com
Wed Jun 23 08:53:42 CDT 2004


Chris asks:
> By that same token, 

Pun intended?

> what if the change that came was to force people
> to just use multiple lines instead of trying to put multiple
> statements on one? 

The current trend is the opposite but it's really no problem.  Since I
explicitly indicated the end of my statements with a semi-colon, I can use a
simple Perl, awk, VB, tr, etc. script/program to translate the semi-colon
into a CR, LF or CR/LF as needed by the targeted operating system.  Without
the semi-colon, my translation routine would have to know all of the
assumptions that a JavaScript interpreter would make, including the
different assumptions that Jscript might be from ECMA, or version 1.0, 1.1,
1.2, 1.x, etc.  Being explicit makes life easier.

> I have no idea how the language was intended, but I believe
> readability in code almost always prevails over 'slickness' or how
> compact it is (at least
> that's the case in more modern langauges as space isn't a constraint
> like it once was), so that would lead me to believe the semicolon may
> have been put in as an afterthought for people who went shoot the
> latter 2... 

As part of my job, I probably modify more code than I generate.  Most of the
"slickness" I run into is when the original programmer relies on default
behaviors.  The purpose of the semi-colon is probably not for human
readability, it's for the parser in the compiler or interpreter.  Web pages
that are well-form (and have a doctype declared) will render faster than a
web page that is missing end tags or has mixed closing tags.  The
compiler/interpreter has to make assumptions and that costs cycles.

Anyway, this thread is getting a tad bit on the religious side.  I've given
my opinion and my experiences that have led up to it.  Take what you like
from this but feel free to do what works for you and the people who maintain
and use your code.

Mark W.





More information about the Javascript mailing list