RFD: How To Recognize Bad Javascript Code

  • Thread starter Jeremy J Starcher
  • Start date
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
, Wed, 9 Jan 2008 23:35:57, Jeremy J Starcher <[email protected]> posted:

I have a page on my site that lists used bikes, the page is automagically
built from my used-bike list.

During the summer we run out of used bikes. We'll go 3-4 months before
we have any available on our floor. (Just not that many out there --
tight market here.)

I field dozens, if not hundreds, of calls all saying that "You never
updated your used bike page! What use is that!"

So yes, there is a need to show that a page has been modified even if
none of the contents have changed. If it will field the calls, I'll have
the web page updated once a day. Touching the file on the server would
be easiest... just run a cron job.

No. The need is not to say that the list has been modified, but to say
that the list has not needed to be modified. That of course requires
the delivered page to be modified.

You need in fact two dates; one for the most recent change in the list,
and one for how up-to-date the list actually is. The latter could be
done by CRON, provided that the list-change process, when needed, is
correspondingly prompt and reliable.

If you keep changing Last-Modified, and keep displaying it with
corresponding words, and do not display the list-changed date, your
users will keep reading the list and finding no difference. They will
be annoyed.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Dr J R Stockton said the following on 1/10/2008 7:13 AM:

No, the identifier is *very* indicative of what it gives you. It gives
you the date the document was last modified.

It seems possible that we might agree that the last-Modified header
corresponds to the current datestamp of the file.

Wayne has recently pointed out that, in some systems, one can change the
content of the file without changing that datestamp.

I have pointed out that one can re-upload with identical content,
causing only the datestamp to change.

Therefore, the datestamp is only a weak guide to the real date of the
contents of the page.

Consider a page containing only the words of, say, the Gettysberg
Address. It seems unlikely that Abe uploaded them to a server at the
time, but they have no doubt been reverently uploaded since. If there
is a long-standing Web page containing only those words under the
obvious heading, and it is moved to a new system which, for the
convenience of such as yourself, appends a lastModified statement to
each page, do you think it right to have words whose meaning is that the
Address has recently been modified?

And that identifier is.

Maybe document.serverFileDatestamp for example; fileDate if something
shorter is preferred. Of course, the Last-Modified header needs a
corresponding change. It won't happen; but programmers need to realise
that the names were badly chosen. See "—And He Built a Crooked House—".
document.lastModified is nowhere near a misnomer. It is precisely what
it says it is.

Not for those who know what "modified" means in ordinary English.

You are the one that seems to think it always indicates "potential
significance" which isn't what the property holds.

I have been saying that the naive scripter may believe that; and that it
is quite likely that the reader of a page whose source contains
something like
document.write("Last Modified at : ", document.lastModified, "<br>")
will believe that what he sees was last changed then.

Out of curiosity though, could you explain what rules you think an OS
should follow to know whether a document has truly been modified -
according to your expectations - versus minor corrections?


It cannot do so. Therefore, it should not emit dates in association
with identifiers which imply that that is the case. The information
needs to be inserted at the place where the document is actually edited.
 
T

Thomas 'PointedEars' Lahn

Richard said:
So javascript's try/catch implies the need to catch all exceptions and
then identify the exception caught to see if it is an expectation that
can be handled, and re-throw those that cannot be handled.

That applies to other ECMAScript implementations, but not to JavaScript
anymore since version 1.5.
But the ability to identify exceptions is so limited/problematic that
you would be hard pressed to find any single example of anyone actually
coding this.

It is rather that few people know that in JavaScript 1.5+ one can handle
only certain exceptions.

http://PointedEars.de/es-matrix#try
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:try...catch


PointedEars
 
T

Thomas 'PointedEars' Lahn

Richard said:
Maybe not guaranteed but it has generally been observed that a syntax
error in the contents of one script element (or in a resource imported
by a single script element) does not interfere with the successful
interpretation/compilation of syntax error free code in other script
elements (or imported by other script elements) within the same
document. Any cited examples where it did would be important, but in
their absence this seems excessively paranoid.

That would be a voodoo programmer's argument. I don't buy it.


PointedEars
 
T

Thomas 'PointedEars' Lahn

McKirahan said:
Jeremy J Starcher said:
(Request for Discussion)

I've put together a guide that I hope will help novice coders avoid the
same hair pulling that I went through.

[snip]

You guys could probably have a field day with this script!
http://www.curvycorners.net/rounded_corners_lite.inc.js

A reference to a supposedly bad script posted here
and instantly it becomes 404-compatible. I like that :)


SCNR

PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Yes it does. Perhaps you could post a definition of what you think
"modified" means in "ordinary English".

modify verb (modifies, modified, modifying) 1 to change the form or
quality of something, usually only slightly. 2 grammar to act as a
modifier of (a word). 3 to moderate. modifiable adj. modification noun 1
the act of modifying or state of being modified. 2 a change of form or
condition; something that has been modified • a few modifications to the
original plan.
ETYMOLOGY: 14c: from French modifier, from Latin modificare.
And when you save a file, it is "altered" in that it was replaced.

If the saved version has the same content, byte for byte, it is not
modified.

If a new version of an HTML file displays identically in a browser, it
is not modified.

If the content of a file is altered, but the datestamp is unchanged, the
file is modified.

Therefore, Last-Modified and lastModified are misnomers.

misnomer noun 1 a wrong or unsuitable name. 2 the use of an incorrect
name or term.
ETYMOLOGY: 15c: from French mesnommer to misname, from mes- mis- +
nommer to name, from Latin nominare.




ASIDE: LZZ is modified, matching the mod to LZ. <js-date9.htm>.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
The OS has no way of knowing that. It is replace. The date it was saved
has changed (which is part of the file), so, the file has been
"modified' (By your own definition).

The datestamp is not part of the file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top