473,572 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Top warning signs of bad code?

It seems most people get there JS off web sites, which is
entirely logical. But it is also a great pity since most
of that code is of such poor quality.

I was looking through the JS FAQ for any question that
identifies the warning signs to look out for, the things
that most easily and clearly identify the author of code
as something less than a master of the art.

I did not find an FAQ that answered it, but I think the FAQ
should contain the info., so, here is my proposed list..

<FAQENTRY class='more_Spe culative_For_Di scussion_OK?'>
1 <SCRIPT LANGUAGE='JavaS cript'> // last millenium, or another reality?
2 if (navigator.user Agent.indexOf(" IE")) // #FAQ4_26
3 eval(); // #FAQ4_40 (usually)
4 if (..==true) // !understanding boolean.
5 <a href="javascrip t:somefunction( )"> // #FAQ4_24
6 <NOSCRIPT> // If missing, the script does not degrade gracefully.
7 document.write( "<p>Importa nt content.."); // delivering content.
</FAQENTRY>

What is your opinion? Are these the top 7?
Which 28 did I miss?

Also, why does the FAQ not contain the words "degrade",
"graceful" or "noscript" (I guess I might have been
looking for the wrong term with the first two, but
no mention of NOSCRIPT? That surprised me.)

BTW - The Jibbering JS FAQ is the single greatest FAQ*
I use, but I just have a hankerin' to get mentioned in
it, or at least contribute to it. ;-)

* I have my own (fledgling) Java FAQ that I hope might
approach the quality of the JS FAQ one day, and am a
contributor to the recently expanded and improved
c.i.w.a.s. FAQ.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05
109 5790
Jim Ley wrote:
Hmm, I don't agree with this, there's always more reliable ways to do
the same - especially with IE service packs removing the ability to
script the resulting document (when somefunction returns a document).


Wait, what? Does SP2 remove the ability for a function to return the
document?
How about including the source inlike like javascript:'<ht ml>...' ?

I've not yet loaded SP2, but I'm trying to get a machine loaded with it to
see what all might be affected.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #21
On Mon, 20 Sep 2004 09:03:55 -0500, "Matt Kruse"
<ne********@mat tkruse.com> wrote:
Jim Ley wrote:
Hmm, I don't agree with this, there's always more reliable ways to do
the same - especially with IE service packs removing the ability to
script the resulting document (when somefunction returns a document).


Wait, what? Does SP2 remove the ability for a function to return the
document?
How about including the source inlike like javascript:'<ht ml>...' ?


No, it doesn't prevent it, it (actually I think it was a different
hotfix) stops you scripting it - so whilst you could go

<iframe src="javascript :<body>test</body>">

iframeref.docum ent.write( ... )

You can no longer do so - equally you have similar problems with
iframes without a src.

Jim.
Jul 23 '05 #22
On Mon, 20 Sep 2004 07:01:00 -0700, Douglas Crockford wrote:
0. It does not pass JSLINT. http://www.crockford.com/javascript/lint.html


Thanks Douglas. I had seen reference to it before,
but it had not occured to me to investigate automated
means of script checking.

Yes. 'The 0th law of JS validation' sounds a bit
'I Robot' though, so I'm inclined to slot it in at #1
and adjut the others, when an outomated tool can detect
errors, it .
_______________ ______
As an aside, I have also linked to it from my
page on preparing examples for others..

<http://www.physci.org/codes/sscce.jsp#co>

...it is a concept that I promote widely on the Java
groups particularly. New posters on c.l.j.* are even
beginning to refer to example Java codes as SSCCE's! ;-)

I do not mention that page much in c.l.js, but it, in
combination with Spartanicus' page on web-page/styles
examples*, might help communicate the idea that a well
prepared example is much more likely to get attention
and to be solved.

* <http://www.spartanicus .utvinternet.ie/help_us_help_yo u.htm>

The JS FAQ covers most of the points I make in my SSCCE
page, but they are spread throughout the FAQ, and often
mentioned as a small part of volumes of other information.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #23
On Mon, 20 Sep 2004 12:57:28 GMT, Andrew Urquhart wrote:
http://www.developer-x.com/content/innerhtml/


Thanks Andrew, I've bookmarked that and will have a
close look over it when I get the chance.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #24
On Mon, 20 Sep 2004 15:03:32 GMT, Andrew Thompson wrote:
Yes. 'The 0th law of JS validation' sounds a bit
'I Robot' though, so I'm inclined to slot it in at #1
and adjut the others, when an outomated tool can detect
errors, it .


I apparently did not insert enough change for that
paragraph, I'll try it again.

"..so I'm inclined to slot it in at #1 and adjust the
others accordingly. When an automated tool can detect
errors, it makes sense to use it as the first line
of attack for solving problems."

Yes.. yes that's better.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #25
Jim Ley wrote:
No, it doesn't prevent it, it (actually I think it was a different
hotfix) stops you scripting it - so whilst you could go
<iframe src="javascript :<body>test</body>">
iframeref.docum ent.write( ... )
You can no longer do so - equally you have similar problems with
iframes without a src.


I'd like more info about this. Do you have a test case?

In my version of IE6 - which is completely up-to-date except for SP2 - I can
do a document.write( ) to an iframe document without any problems.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #26
Lee
Andrew Thompson said:

On Mon, 20 Sep 2004 15:03:32 GMT, Andrew Thompson wrote:
Yes. 'The 0th law of JS validation' sounds a bit
'I Robot' though, so I'm inclined to slot it in at #1
and adjut the others, when an outomated tool can detect
errors, it .


I apparently did not insert enough change for that
paragraph, I'll try it again.

"..so I'm inclined to slot it in at #1 and adjust the
others accordingly. When an automated tool can detect
errors, it makes sense to use it as the first line
of attack for solving problems."


Keep in mind that it detects *probable* errors.
A few of the things it flags are useful if used carefully
and the intention is well documented. I don't think it
would flag anything in any of my production code, but I
wouldn't trust it blindly to declare code to be "bad".

Jul 23 '05 #27
Matt Kruse wrote:
Jim Ley wrote:
No, it doesn't prevent it, it (actually I think it was a different
hotfix) stops you scripting it - so whilst you could go
<iframe src="javascript :<body>test</body>">
iframeref.doc ument.write( ... )
You can no longer do so - equally you have similar problems with
iframes without a src.

I'd like more info about this. Do you have a test case?

In my version of IE6 - which is completely up-to-date except for SP2 - I can
do a document.write( ) to an iframe document without any problems.


<script type="text/javascript">
function changeIFrame(){
myIFrame.docume nt.write('new Content')
myIFrame.close( )
}

<body onload="changeI Frame()">

<iframe src="javascript :'<body>test</body>'" id="myIFrame"
name="myIFRame' onload="alert(t his.src)"></iframe>

Seems to work in IE6 SP2 on WinXP SP2.

So I am not sure what Jim is alluding to.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #28
JRS: In article <yc************ *************** **@40tude.net>, dated
Sun, 19 Sep 2004 23:42:04, seen in news:comp.lang. javascript, Andrew
Thompson <Se********@www .invalid> posted :
It seems most people get there JS off web sites, which is
entirely logical. But it is also a great pity since most
of that code is of such poor quality.

I was looking through the JS FAQ for any question that
identifies the warning signs to look out for, the things
that most easily and clearly identify the author of code
as something less than a master of the art.
Another one is spelling/grammar errors, at least in the case of those
who seem to be writing in there native language <G>.

I did not find an FAQ that answered it, but I think the FAQ
should contain the info., so, here is my proposed list.. 4 if (..==true) // !understanding boolean.
include ..==false
6 <NOSCRIPT> // If missing, the script does not degrade gracefully.
On the whole, agreed. Although a well-designed site may look
magnificent with scripting, and adequately excellent without, the
scripting should only be used if it adds value; a user who does not get
this value should be informed that added value is available. This
probably justifies at least one NOSCRIPT, but does not require one for
every SCRIPT.

7 document.write( "<p>Importa nt content.."); // delivering content.


Such a line is valid as the beginning of a section of computed content.

Also :

Use of getYear, especially if combined with unreliable "century" code,
and more so if that code fails for dates after 1999.

Use of 24*60*60*1000 and vice versa, rather than 864e5 or 86400000; use
of that number in a manner which will fail across Summer Time changes,
or away from GMT.

Others in <URL:http://www.merlyn.demo n.co.uk/js-dates.htm#SPF>.

Presenting dates in FFF.

--
John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #29
"Richard Cornford" <Ri*****@litote s.demon.co.uk> writes:
<SCRIPT LANGUAGE='JavaS cript1.2'> - is more indicative of out of date
and ill-informed authoring.
Definitly, that goes from just bad to directly dangerous.
.... as the LANGUAGE attribute will never directly harm a script in an
HTML browser in itself.


Sure it will. Try running the following in Mozilla and IE, and wonder
why they give different results.
---
<script language="JavaS cript1.2">
var y = {someObject: false};
//...maybe some code that *could* do "y=null", but didn't
var x;
if (x = y) {
alert("x is now equal to y");
} else {
alert("y was not an object");
}
</script>
---
Writing language="JavaS cript1.2" is explicitly asking for trouble!
I know, it's not a good idea to have an assignment in a condition,
but it's valid Javascript.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.