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
  #101  
Old   
RobG
 
Posts: n/a

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






On Jan 8, 8:50 am, Jeremy J Starcher <r3... (AT) yahoo (DOT) com> wrote:
Quote:
On Mon, 07 Jan 2008 17:11:40 -0500, Randy Webb wrote:
Jeremy J Starcher said the following on 1/7/2008 4:58 AM:
On Tue, 01 Jan 2008 05:37:14 -0500, Jeremy J Starcher wrote:
Most of these, if not all, are grammar and typo related:

Bad fingers! Bad!

The joys of being dyslexic. Normally, one of my friends is willing to
proofread things for me and catch all of that stuff before it hits the
world, but she won't proofread tech documents.
You can also try:

1. Copy and paste into a word processeor and do a spelling and grammar
check

2. Use text-to-speech and listen to it read back to you (it can
usually be set to run off hotkeys)

Quote:
I even did the old "get away from it for a few days" trick to see if I
could spot anything I didn't catch last time through.
A useful trick, but the law of diminishing returns still applies - it
becomes less effective the more you do it on a particular document.


Quote:
Hopefully, edits should be just about over.
It will never end. :-)


Quote:
(Mentally, I know there is a difference between "depreciated" and
"deprecated" but I don't *see* it, if that makes any sense.)
Hence find and replace...

--
Rob


Reply With Quote
  #102  
Old   
Anthony Levensalor
 
Posts: n/a

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






Wayne said:

Quote:
You should join the group "DAM", Mothers Against Dyslexia.

I know that's just wrong, but I'm laughing anyway.

~A!

--
anthony at my pet programmer dot com


Reply With Quote
  #103  
Old   
David Mark
 
Posts: n/a

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



On Jan 7, 4:58*am, Jeremy J Starcher <r3... (AT) yahoo (DOT) com> wrote:
Quote:
On Tue, 01 Jan 2008 05:37:14 -0500, Jeremy J Starcher wrote:
(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.

URL:http://www.mopedepot.com/jjs/HowToRe...criptCode.html

Version 0.3 is up.

You might want to add a note to avoid anything that is written on top
of Prototype.js (or jQuery of course.)

I recently stumbled onto this prototypical (no pun intended) example
of bad code:

http://dev.rubyonrails.org/changeset/7056

Why would anybody write script like this, knowing they will have to
rewrite it constantly, just to keep up with four browsers? Perhaps
they just like monkeying around with code. Obviously these million
monkeys are never going to write Hamlet.

Their repository is full of gems like this. Their various blogs and
mailing lists are full of frantic bickering over the latest exposed
misunderstandings. Typically they cover them with browser sniffing
patches that most production sites don't see until after their
relative effectiveness has expired. In the meantime, exceptions like
"Event.observer is not an object" pop up everywhere.

Any programmer who builds on top of such jello must be out of their
minds. The fact that Prototype and the like are in widespread use
would seem to indicate some sort of mass hysteria among Web developers.


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

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-08-2008 , 06: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:
Quote:

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

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.

--
(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
  #105  
Old   
Randy Webb
 
Posts: n/a

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



Dr J R Stockton said the following on 1/8/2008 7:47 AM:
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.


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.



--
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
  #106  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

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



Dr J R Stockton wrote:
Quote:
[...] Randy Webb [...] 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);
Correct. But maybe that is because it is only a beta.

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.

Quote:
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; [...]
Fortunately, you are wrong here as well, and programming languages that are
used server-side make this a lot easier. For example, I use essentially

<?php
$modi = @filemtime(__FILE__);
echo gmdate('Y-m-d\TH:i:s+00:00', $modi);
?>

in <URL:http://PointedEars.de/es-matrix>.

Quote:
Eschew FFF.
JFTR: "FFF" probably means "Fred Flintstone Format" here, the mm/dd/yyyy
date format as it is used in Canada, the Federated States of Micronesia, the
Republic of Palau, the Republic of the Philippines, and in the United States
of America.

http://acronyms.thefreedictionary.com/FFF

(CMIIW)


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann


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

Default Re: RFD: How To Recognize Bad Javascript Code v0.3 - 01-09-2008 , 07: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:
Quote:
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.

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.[*]

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.



ASIDE : I now have an improved Leading Zero function, LZ; it is the
fastest (in IE6) of three which all, AFAICS, always give the right
answer. See <js-tests.htm#LZ>.

function LZ(x) { return (x!=null&&x<10&&x>=0?"0":"") + x }

[*] I have a nice story about typos and random numbers ...

--
(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
  #108  
Old   
Wayne
 
Posts: n/a

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



Dr J R Stockton wrote:
Quote:
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).

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.

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.)

-Wayne


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

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



In comp.lang.javascript message <47840944.2000000 (AT) PointedEars (DOT) de>, Wed,
9 Jan 2008 00:37:40, Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de>
posted:
Quote:
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. The fact remains that
the string is empty in Sf 3.0.4.

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.

Quote:
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; [...]

Fortunately, you are wrong here as well, and programming languages that are
used server-side make this a lot easier. For example, I use essentially

?php
$modi = @filemtime(__FILE__);
echo gmdate('Y-m-d\TH:i:s+00:00', $modi);
?
The datestamp of a file is not necessarily the date of the last
modification to its contents; and that is not necessarily the last
modification that the page's reader will need to know about.

To consider the datestamp of any file to be *necessarily* important to
the average user of the file is naive.

--
(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.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.


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

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



Dr J R Stockton wrote:
Quote:
[...] 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.

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?

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.

Quote:
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; [...]
Fortunately, you are wrong here as well, and programming languages that are
used server-side make this a lot easier. For example, I use essentially

?php
$modi = @filemtime(__FILE__);
echo gmdate('Y-m-d\TH:i:s+00:00', $modi);
?

The datestamp of a file is not necessarily the date of the last
modification to its contents; and that is not necessarily the last
modification that the page's reader will need to know about.
True, but in my case it will suffice until I make the ES Matrix more dynamic.

Quote:
To consider the datestamp of any file to be *necessarily* important to
the average user of the file is naive.
You are jumping to conclusions.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>


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.