In comp.lang.javascript message <
[email protected]
am.me.not.com>, Tue, 1 Jan 2008 05:37:14, Jeremy J Starcher
The encoding of the page seems undefined, causing the W3C Markup
Validator to emit /inter alia/ a split infinitive. Try Opera Ctrl-Alt-V
or otherwise. I think that
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
or similar will deal with the matter, if you cannot do better with
server settings.
The page is unusually good in that it does not overrule my choice of
font face and size; but it is bad in using boxes of light text on dark
background. Use black-on-light, discriminating by hue-of-light and/or
colour of border.
"Rational" should be "Rationale".
"When I first started to learn Javascript, I turned to Google for
examples and code snippets." - that's an almost completely reliable way
of getting bad code.
Another good sign of bad code is any sign of an automated code
generator, unless specifically known to be good.
Code within a proportional sentence needs to be monospace - e.g.
" things, Document.write's limitations " to be
" things, <code>document.write</code>'s limitations " (small d, too).
Text should not abut a colour-change - leave padding.
"import compability code" - spelling.
The page does not indicate any way of contacting the author; that
inhibits feedback.
The page lacks date or version number (apart from copyright 2008);
without those, the re-visitor cannot see whether re-reading may be
worthwhile.
The page lacks any link to a site home page or similar.
The page lacks a link to this newsgroup and its FAQ.
You have "All variables should be declared before their use." In
Pascal, "before" implies "higher up the page"; in Javascript, it may
mean "earlier in time". Clarify. In addition, the scope of variables
should be local wherever reasonable. ISTM that you mean, but do not
really say, that.
I don't like the idea of liberating the chlorine from one or two grains
of salt - when being clever, one needs also to be right.
"Permission granted to reproduce in any form ..." - Unwise. Copies
that are not updated are a disservice to their readers. Google for
exactly "other critical date lists at Cinderella" to see what I mean.
" with a ending with " - should be "an"
"from an an online "
"The eval statement allowes any "
"interfer with other browsers"
"to use use a valid "
There are many other indicators of bad code, some substantially
language-independent.
One is superfluous recalculation, as in
document.getElementById("cat").style.font = "Tahoma"
document.getElementById("cat").style.size = "88%"
where of course the cat only needs to be found once -
puss = document.getElementById("cat") ; ...
Another is (multi-)duplication of code with slight modification, as is
often seen in validation of inputs to be non-empty. Use instead a
function with parameters.
A JS-specific one is date object duplication by
D2 = new Date(D1) ; .
Another JS-specific one is conversion of String to Number by any means
other than unary + in a case where unary + serves.
IMHO, the type returned by a function should not vary unexpectedly with
input value or type. To convert a positive integer Number to a string
of at least 2 digits, function DD(J) { return J>9 ? J : "0" + J } ;
may return String or Number. Generally that won't matter, especially in
test. Sometimes it will matter.
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.