![]() | |
#31
| |||||||||
| |||||||||
|
|
Jeremy J Starcher said the following on 1/1/2008 5:37 AM: On Tue, 01 Jan 2008 05:28:51 -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. And it would really help if I included URL:http://www.mopedepot.com/jjs/HowToRe...criptCode.html HTML Comments. * Will cause problems when XHTML is used. Script tag usage. * text/javascript is an obsolete (although valid) MIME type. |
|
href:javascript. * Drop #1, they all fall into the "Too stupid to know better" category. document.write. * Avoid it. Period. |
|
* Tables produced with document.write are indicative of an idiot programmer. |
|
* As for minification, that is an indication of bad coding practices. |
|
Use of eval. * The use of eval itself usually indicates bad coding, but not always. * Whether it is a bad use of it or not depends on how it is used. * And a beginner can't possibly know. Is this a good use of eval? function convertToDecimal(fraction){ return eval(fraction) } |
|
Where fraction is a fraction that you need converted to decimal? It can be written like this: function convertToDecimal(fraction){ var numerator = fraction.substring(0,fraction.lastIndexOf('/')) var denominator = fraction.substring(fraction.lastIndexOf('/')+1) return (numerator/denominator) } Testing shows that eval is a lot quicker but a newbe could never know that it was actually a "good use" of eval. |
|
Browser detection. * Spelling error with interfer versus interfere. DOCTYPE. * No version of IE, not just IE7, handles it that way. JSLint. * JSLint is a tool that attempts to make sure you code * according to the preference and style that Douglas Crockford * prefers. |
|
Things you didn't cover: The use of the "with" operator. |
|
Use of "new Function". |
#32
| |||
| |||
|
|
On Tue, 01 Jan 2008 13:38:43 -0500, Randy Webb wrote: [snip] try/catch is another of the things you didn't cover. Don't use it. I've not used try/catch in Javascript myself, but I've done reading on it. According to <URL:http://www.w3schools.com/js/js_try_catch.asp try...catch statement is available in IE5+, Mozilla 1.0, and Netscape 6. *Googling says Opera and KHTML both have it. |
|
I don't understand the concern ... *are there common browsers out there that don't support it? *I've heard rumors about mobile devices, but nothing concrete. * |
#33
| ||||
| ||||
|
|
On Tue, 01 Jan 2008 15:32:47 -0500, Randy Webb wrote: Jeremy J Starcher said the following on 1/1/2008 2:38 PM: On Tue, 01 Jan 2008 13:30:25 -0500, Randy Webb wrote: Not to name names, but had I the skill to recognize URL: http://www.dynamicdrive.com/ > for what it was, I wouldn't have had to unlearn so much. Some of the first copy/paste scripts I ever used came from there. It took a while for me to understand what was wrong with them. The first tutorial I ever went through (web-based) was on the HTMLGoodies site when Joe Burns was writing them. Not the best quality but at the time the best I could find. Was enough to "Get my feet wet" and obtain the desire to know more. Now, I wish a good one did exist. I know the "Code Worth Recommending Project" has taken on some of that. |
|
They are going through some growth pains and sorting out some of the basics. I'd be willing to donate code once they are ready for higher-level functions. |
|
As for a good tutorial: I've actually thought about writing one. Its been over a decade since I've done any real technical writing, but I think I could find the touch again. Like all of us, the trouble is time. |
|
With all the crap on the market, I don't know if my book would actually -sell- and I'd feel obligated to c.l.j for at least -part- of the money I made on the second edition, because the first edition will be red-lettered to death from you guys. *grin* Not a bad thing, but I can't easily post a credit-card number here and say 'Withdraw what you earned.' |

#34
| |||
| |||
|
|
On Tue, 01 Jan 2008 05:28:51 -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. And it would really help if I included URL:http://www.mopedepot.com/jjs/HowToRe...criptCode.html |
#35
| |||
| |||
|
|
Anthony Levensalor wrote: First, I liked your doc, and the comments on it so far have taught me a lot. But you despise the people that made them? *Something doesn't add up here. |
#36
| |||
| |||
|
|
There is also argument over the use of minifiers. I think they are a valid way to reduce code bulk, however zipping code files is probably as effective and doesn't require 2 sets of testing. |
#37
| |||
| |||
|
|
Anthony Levensalor wrote: Thomas 'PointedEars' Lahn posted : b. The term you were looking for is `script' _element_, |
|
Elements consist of tags (start tag, close tag) |
.|
Funny thing is, I looked that page up and down buddy, and I didn't see anything about a script _element_ anywhere. Maybe your underscore is broken. Maybe you are an idiot. (See, *now* I said it.) |

#38
| |||
| |||
|
|
Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de> writes: Anthony Levensalor wrote: Thomas 'PointedEars' Lahn posted : b. The term you were looking for is `script' _element_, script element _type_ |
|
Elements consist of tags (start tag, close tag) The terms you were looking for are start-tag and end-tag. See ISO 8879, clause 7.3, or otherwise not the FAQ, part 5 (and also part 4, now that I come to think about it . |
#39
| ||||||
| ||||||
|
|
On Jan 1, 8:37*pm, Jeremy J Starcher <r3... (AT) yahoo (DOT) spam.me.not.com wrote: On Tue, 01 Jan 2008 05:28:51 -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. And it would really help if I included URL:http://www.mopedepot.com/jjs/HowToRe...criptCode.html Despite the comments here, the page does not seem to have been updated. I'll stick to things others haven't mentioned: |
|
HTML comments The heading should be "HTML comments inside script elements". Depreciated script tag usage In the early days of Javascript and HTML the <script> tag took a "language" parameter. With HTML 4, the language parameter became depreciated. That statement should be something like: "The language attribute was introduced in HTML 4.0, it was immediately deprecated in favour of the type attribute." |
|
URL: http://www.w3.org/TR/WD-html40-97070...html#h-9.2.1.1 Using "href:javascript" Should note that using script for the value of the href attribute probably indicates that a button should be used, not a link. I don't think the term "cargo-cult programming" applies specifically to that section, it is more a general comment about people who copy code or patterns and could be applied to the entire article. Having said that, I wouldn't use it at all. Not declaring local variables (no var) ...causes large and hard-to-find complications. While the thrust of the section is good, it gives the impression that using var stops global variables. Better to explain that: 1. All variables should be declared 2. Global variables should be kept to a minimum 3. Declaring variables inside functions keeps them local 4. Not declaring them inside functions makes them global *when the function is first called*. Also, unintentional global variables *may* cause hard to find bugs, there is no guarantee. |
|
Not ending lines in a semi-colon ";" |
|
Web pages that do not include a DOCTYPE and/or do not validate Whenever you are tempted to use "and/or", don't. One or the other should be used. In any case, the title doesn't make sense. A DOCTYPE is required for valid HTML, therefore if there is no DOCTYPE, the page is not valid HTML. I think the point you are trying to make is something like: Beware of invalid markup Primary causes of invalid markup are: missing DOCTYPE declaration, use of invalid or deprecated tags or attributes, incorrect nesting of elements and missing required or incorrect use of element attributes (e.g. non-unique ID attribute values). All of the above may affect how scripts interact with the DOM and are signs of poor quality markup. It is likely that anyone publishing poor quality HTML applies the same level of quality control to their scripting. |
|
Last of all, remember that it is your document. Ensure readers will not be confused between what is required by standards, what "works" and what doesn't and what is good practice (i.e. opinion). |
#40
| |||
| |||
|
|
a. The word you were looking for is _deprecated_, not "depreciated". |
![]() |
| Thread Tools | |
| Display Modes | |
| |