HighDots Forums  

RFD: How To Recognize Bad Javascript Code

Javascript JavaScript language (comp.lang.javascript)


Discuss RFD: How To Recognize Bad Javascript Code in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #111  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-09-2008 , 04:20 PM






In comp.lang.javascript message <4784d81e$0$7149$4c368faf (AT) roadrunner (DOT) com
Quote:
, Wed, 9 Jan 2008 09:20:15, Wayne <nospam (AT) all4me (DOT) invalid> posted:
Dr J R Stockton wrote:
the current Windows beta (empty string); and that lastModified is a
misnomer because in practice it means "last uploaded to the server".
It is not a misnomer. It reflects the date the document you are viewing
was last modified. It has nothing to do with "uploading". The FAQ
index.html, while I have been editing the FAQ, has *never* been
uploaded. The date that document.lastModified gives is exactly that,
the date that the document was last Modified. Whether that modification
is by uploading a replacement, direct editing on the server, or by
being generated on the server.
Your lack of insight is most impressive.
When a document is, for whatever reason, re-uploaded to a server
(perhaps because of a change of server, for instance), it gets a new
Last-Modified header. But if the content of the document, as seen by
the user, is unchanged, it is a disservice to assert that there has been
a modification. It is also a disservice if the change is too slight to
matter to the reader, for example correcting non-misleading typos.[*]

Surely that depends on how the file was uploaded. For example with the
right options on "rsync" the file's last modified timestamp doesn't
change. (It is this filesystem timestamp that is usually used by a
web server when setting the Last-Modified: header, and hence the
document.lastModified value).
Thank you. That reinforces my point that JavaScript lastModified is
only loosely connected to the actual date/time when the last significant
modification was made or uploaded. <js-date2.htm#lM> adjusted.

Quote:
In short it would depend on the filesystem, the upload method, and the
web server, as to what date is reported. In the common case of using
FTP to upload files the time stamp does change. But rsync, scp,
and other tools can maintain the filesystem's modification timestamp
unless the document was actually modified.
Indeed, 32-bit MiniTrue for Win-32 can edit a local file without
changing the datestamp.

Quote:
Perhaps the way to deal with minor edits and last modification times
is to use a CMS or similar. Or you can add version numbers to your
documents that don't change for minor edits or re-uploads. (A simple
RCS/CVS/SVN/whatever repository will expand special tokens in
the document source into the current version number.)
Agreed.

It's a shame that the lastModified string was not specified to be an
exact copy of the Last-Modified header, which if RFC-compliant specifies
a time without any ambiguity.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
free, DOS/Win/UNIX, <URL:http://www.idiotsdelight.net/minitrue/> unsupported.


Reply With Quote
  #112  
Old   
Randy Webb
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-09-2008 , 04:34 PM






Dr J R Stockton said the following on 1/9/2008 8:52 AM:
Quote:
In comp.lang.javascript message <Npqdnc-N5fxoTR7aRVn_vwA (AT) giganews (DOT) com>,
Tue, 8 Jan 2008 14:38:44, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:
Dr J R Stockton said the following on 1/8/2008 7:47 AM:
In comp.lang.javascript message <sKKdnZ4jENr6Ph_aRVn_vwA (AT) giganews (DOT) com>,
Mon, 7 Jan 2008 17:11:40, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:
document.write("<p>This page last updated:" + document.lastModified) +
"<\/p>");

Extra ) after lastModified.

One should add that the result will look somewhat silly in Safari
3.0.4,
the current Windows beta (empty string); and that lastModified is a
misnomer because in practice it means "last uploaded to the server".
It is not a misnomer. It reflects the date the document you are viewing
was last modified. It has nothing to do with "uploading". The FAQ
index.html, while I have been editing the FAQ, has *never* been
uploaded. The date that document.lastModified gives is exactly that,
the date that the document was last Modified. Whether that modification
is by uploading a replacement, direct editing on the server, or by
being generated on the server.


Your lack of insight is most impressive.
Not near as impressive as your lack of the ability to understand simple
English.

Quote:
When a document is, for whatever reason, re-uploaded to a server
(perhaps because of a change of server, for instance), it gets a new
Last-Modified header.
Precisely. And that is the date that lastModified reads. And it is
*precisely* what it is supposed to read. Any argument that says it
should read otherwise is just plain wrong.

Quote:
But if the content of the document, as seen by the user, is unchanged,
it is a disservice to assert that there has been a modification.
If you use document.lastModified (or the Last-Modified header), to
indicate that to the user, then you deserve what you get. Because that
is precisely the date it holds, the date it was last modified.
Irregardless of how/why it was modified.

Quote:
It is also a disservice if the change is too slight to
matter to the reader, for example correcting non-misleading typos.[*]
Then you prefer to lie to them and tell them it was last modified before
it was last modified? How intuitive and honest of you.

Quote:
Please remember what WSC is alleged to have said about Americans (and if
possible provide an authoritative reference); in this respect, the task
is as yet incomplete.
And please remember what Randy Webb explicitly wrote about a gnats ass
and "Thats nice[1]".

Quote:
[*] I have a nice story about typos and random numbers ...
If it is as dumb and convoluted as your story about
document.lastModified, then keep it to yourself.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #113  
Old   
Jeremy J Starcher
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-09-2008 , 05:35 PM



On Tue, 08 Jan 2008 12:47:39 +0000, Dr J R Stockton wrote:

Quote:
In comp.lang.javascript message <sKKdnZ4jENr6Ph_aRVn_vwA (AT) giganews (DOT) com>,
Mon, 7 Jan 2008 17:11:40, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:


document.write("<p>This page last updated:" + document.lastModified) +
"<\/p>");

Extra ) after lastModified.

The only way to get a date really useful to the normal reader, who will
care only about whether there are significant content changes, is to
type it in to the HTML when a significant change is made; and to do so
in an internationally-standard format. Eschew FFF.
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.



Reply With Quote
  #114  
Old   
Wayne
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-09-2008 , 06:14 PM



Jeremy J Starcher wrote:
Quote:
On Tue, 08 Jan 2008 12:47:39 +0000, Dr J R Stockton wrote:

In comp.lang.javascript message <sKKdnZ4jENr6Ph_aRVn_vwA (AT) giganews (DOT) com>,
Mon, 7 Jan 2008 17:11:40, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:

document.write("<p>This page last updated:" + document.lastModified) +
"<\/p>");

Extra ) after lastModified.

The only way to get a date really useful to the normal reader, who will
care only about whether there are significant content changes, is to
type it in to the HTML when a significant change is made; and to do so
in an internationally-standard format. Eschew FFF.

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.

If the client accepts cookies from your site, it is fairly simple
to check what has changed since the last visit. You can then list
those bikes specially.

-Wayne


Reply With Quote
  #115  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-10-2008 , 06:06 AM



In comp.lang.javascript message <47851FF0.9080501 (AT) PointedEars (DOT) de>, Wed,
9 Jan 2008 20:26:40, Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de>
posted:
Quote:
Dr J R Stockton wrote:
[...] Thomas 'PointedEars' Lahn [...] posted:
Dr J R Stockton wrote:
[...] Randy Webb [...] posted:
document.write("<p>This page last updated:" + document.lastModified) +
"<\/p>");

One should add that the result will look somewhat silly in Safari 3.0.4,
the current Windows beta (empty string);
Correct. But maybe that is because it is only a beta.

The reason is like Mr Worthing's early location.

Sorry, I don't understand.
You were not expected to. You are an uncultured person of narrow
"education". If you should come to wish to improve yourself, it is of
importance that you should take earnest steps to remedy that.


Quote:
The fact remains that the string is empty in Sf 3.0.4.

It is empty in the _beta_ version. Don't you think that this could *maybe*
be a bug that is fixed for the release?
Of course it could be, Pooh. Or, of course, they might not do so.
Nevertheless, the string is empty in 3.0.4.


There's another strange discrepancy between the behaviour of Safari and
that of IE, FF, and Opera when handling years above 275000 or
thereabouts, detected in <js-date8.htm> (that shows a different Opera
error, too); I'd like to understand it better before reporting it.
Other discrepancies have been reported.


Quote:
and that lastModified is a misnomer because in practice it means "last
uploaded to the server".
Incorrect. The `lastModified' property shows the modification time of the
resource, essentially the value of the `Last-Modified' HTTP header. The
upload time to the server does not enter into it, although the modification
timestamp of a file is usually also set/updated when it is created or
overwritten in the filesystem as it would happen during an upload.

You are once more revealing your background as an unintelligent product
of a technical college; one who can regurgitate material but cannot
think effectively. In many respects, you and Randy are equals.

You have stated that the `lastModified' property value would mean the date
of the last upload to the server, which is simply wrong. It would look
better on your record if you had the courage to admit your error that
instead of hiding behind your inept attempts at ad hominem attacks. But I
guess that is too much to ask for.
Don't use terms such as /ad hominem/ until you understand their proper
meaning - which is likely to be distinct from US usage. An /ad hominem/
example would be to say "KV's statement is wrong because KV is an
idiot", that's quite distinct from saying "KV is an idiot because KV's
statement is wrong".

One does not object to the written consequences of your abnormal
personality because they are written by you; one objects to your
abnormal personality because of what you write.


"Last-Modified" and "lastModified" should have been given a name
corresponding exactly to what they are - probably something like "File-
Datestamp". As it is, the naive programmer reports it as if it were
necessarily something significant to the3 reader of the page.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Delphi 3? Turnpike 6.05
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.html> news:borland.* Guidelines


Reply With Quote
  #116  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-10-2008 , 06:13 AM



In comp.lang.javascript message <RJ-dnaI8yOEa1hjaRVn_vwA (AT) giganews (DOT) com>,
Wed, 9 Jan 2008 17:34:28, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:
Quote:
Dr J R Stockton said the following on 1/9/2008 8:52 AM:
In comp.lang.javascript message <Npqdnc-N5fxoTR7aRVn_vwA (AT) giganews (DOT) com>,
Tue, 8 Jan 2008 14:38:44, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:
Dr J R Stockton said the following on 1/8/2008 7:47 AM:

One should add that the result will look somewhat silly in Safari
3.0.4,
the current Windows beta (empty string); and that lastModified is a
misnomer because in practice it means "last uploaded to the server".
It is not a misnomer. It reflects the date the document you are viewing
was last modified. It has nothing to do with "uploading". The FAQ
index.html, while I have been editing the FAQ, has *never* been
uploaded. The date that document.lastModified gives is exactly that,
the date that the document was last Modified. Whether that modification
is by uploading a replacement, direct editing on the server, or by
being generated on the server.
Your lack of insight is most impressive.

Not near as impressive as your lack of the ability to understand simple
English.

When a document is, for whatever reason, re-uploaded to a server
(perhaps because of a change of server, for instance), it gets a new
Last-Modified header.

Precisely. And that is the date that lastModified reads. And it is
*precisely* what it is supposed to read. Any argument that says it
should read otherwise is just plain wrong.
Indeed, according to its definition. But not according to the meaning
of its identifier, and such identifiers should be correctly meaningful.
That corresponds to the meaning of "misnomer".


Quote:
But if the content of the document, as seen by the user, is unchanged,
it is a disservice to assert that there has been a modification.

If you use document.lastModified (or the Last-Modified header), to
indicate that to the user, then you deserve what you get. Because that
is precisely the date it holds, the date it was last modified.
Irregardless of how/why it was modified.
That is how it is commonly used on the Web, displayed in a manner that
will be taken by the normal reader as implying a change of potential
significance to himself.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)


Reply With Quote
  #117  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-10-2008 , 05:19 PM



In comp.lang.javascript message <xTchj.6575$se5.855 (AT) nlpi069 (DOT) nbdc.sbc.com
Quote:
, Wed, 9 Jan 2008 23:35:57, Jeremy J Starcher <r3jjs (AT) yahoo (DOT) com> 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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.


Reply With Quote
  #118  
Old   
Randy Webb
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-12-2008 , 12:51 AM



Dr J R Stockton said the following on 1/10/2008 7:13 AM:
Quote:
In comp.lang.javascript message <RJ-dnaI8yOEa1hjaRVn_vwA (AT) giganews (DOT) com>,
Wed, 9 Jan 2008 17:34:28, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:
Dr J R Stockton said the following on 1/9/2008 8:52 AM:
In comp.lang.javascript message <Npqdnc-N5fxoTR7aRVn_vwA (AT) giganews (DOT) com>,
Tue, 8 Jan 2008 14:38:44, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:
Dr J R Stockton said the following on 1/8/2008 7:47 AM:

One should add that the result will look somewhat silly in Safari
3.0.4,
the current Windows beta (empty string); and that lastModified is a
misnomer because in practice it means "last uploaded to the server".
It is not a misnomer. It reflects the date the document you are viewing
was last modified. It has nothing to do with "uploading". The FAQ
index.html, while I have been editing the FAQ, has *never* been
uploaded. The date that document.lastModified gives is exactly that,
the date that the document was last Modified. Whether that modification
is by uploading a replacement, direct editing on the server, or by
being generated on the server.
Your lack of insight is most impressive.
Not near as impressive as your lack of the ability to understand simple
English.

When a document is, for whatever reason, re-uploaded to a server
(perhaps because of a change of server, for instance), it gets a new
Last-Modified header.
Precisely. And that is the date that lastModified reads. And it is
*precisely* what it is supposed to read. Any argument that says it
should read otherwise is just plain wrong.

Indeed, according to its definition.
Wow. I am impressed. It only took 12 or so posts for you to finally
admit what everyone else knew all along.

Quote:
But not according to the meaning of its identifier,
No, the identifier is *very* indicative of what it gives you. It gives
you the date the document was last modified.

Quote:
and such identifiers should be correctly meaningful.
And that identifier is.

Quote:
That corresponds to the meaning of "misnomer".
document.lastModified is nowhere near a misnomer. It is precisely what
it says it is. The only way it could come close to being misleading is
that the identifier isn't document.dateLastModified. What you seem to
want it to be is some type of document.lastContentEdited type date and
the OS simply has no way to automatically figure that out. And, if you
make it user configurable (which some OS'es seem to allow), then you
relegate it navigator.userAgent status which is useless.

Quote:
But if the content of the document, as seen by the user, is unchanged,
it is a disservice to assert that there has been a modification.
If you use document.lastModified (or the Last-Modified header), to
indicate that to the user, then you deserve what you get. Because that
is precisely the date it holds, the date it was last modified.
Irregardless of how/why it was modified.

That is how it is commonly used on the Web, displayed in a manner that
will be taken by the normal reader as implying a change of potential
significance to himself.
You are the one that seems to think it always indicates "potential
significance" which isn't what the property holds.

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?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #119  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-12-2008 , 12:48 PM



In comp.lang.javascript message <7dydnX2_8cW6_hXaRVn_vwA (AT) giganews (DOT) com>,
Sat, 12 Jan 2008 01:51:14, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:
Quote:
Dr J R Stockton said the following on 1/10/2008 7:13 AM:

But not according to the meaning of its identifier,

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?


Quote:
and such identifiers should be correctly meaningful.

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—".

Quote:
That corresponds to the meaning of "misnomer".

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.


Quote:
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.


Quote:
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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)


Reply With Quote
  #120  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: RFD: How To Recognize Bad Javascript Code - 01-12-2008 , 02:46 PM



Richard Cornford wrote:
Quote:
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.

Quote:
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...:try...cat ch


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.