![]() | |
#61
| |||
| |||
|
|
Randy Webb wrote: Thomas 'PointedEars' Lahn said the following on 1/2/2008 9:13 AM: 2. Using "href:javascript" should be changed into 'Using href="javascript:..."'. The "better example" should be a href="myhouse.jpg" onclick="showPicture(this.href); return false;" Look! My house!</a which would demonstrate that graceful degradation does not imply double maintenance. And an even better solution would be: a href="myhouse.jpg" onclick="return showPicture(this.href)" Look! My house!</a It was a better solution where a popup window was involved. But it would require an additional explanation of the return value of showPicture(), which is why I did not propose it. |
#62
| |||
| |||
|
|
Thomas 'PointedEars' Lahn posted : This is an excellent tip, thanks! It's a recipe for disaster. Whenever you use scripts that use try..catch as-is, compilation will fail with a SyntaxError. Compilation of the other scripts, that you use along with them and that don't use try..catch, is not guaranteed. |
|
It does not matter at all whether script A uses features that are defined in script B, compilation is done in order of inclusion. Since loading script resources dynamically is error-prone, the best thing you can do for now is a) to avoid try...catch entirely or -- where that is not possible or feasible, such as in XHR scripts -- b) to use eval to hide it, what I proposed. |
|
I did some more reading after I posted that, actually, and I was starting to come to that same line of thought, albeit not with any real confidence. Thanks for the tip, I think I'll avoid them entirely for the time being and use another method for making sure my code isn't going to bomb. As a Java developer, try/catch/throw/finally were staples of my existence, and I naturally transitioned that. But, as has been said many, many times here, Javascript is not Java. ![]() |
#63
| |||
| |||
|
|
So any discussion of indictors of bad code can validly mention the use of try/catch because many specific patterns in its use are very indicative of bad code. |
#64
| |||
| |||
|
|
The page lacks any link to a site home page or similar. By design. I don't have a personal home page nor do I have a computer related page anywhere. The page is hosted on a work server with permission. |
|
I don't like the idea of liberating the chlorine from one or two grains of salt - when being clever, one needs also to be right. With a "rule of thumb" it is much harder to define "right." In practice I strongly discourage use of document.write. In practice, I use it sparingly. |
|
"Permission granted to reproduce in any form ..." - Unwise. Copies that are not updated are a disservice to their readers. Google for exactly "other critical date lists at Cinderella" to see what I mean. I will Google for that later. Do you have a licence template that you recommend? |
#65
| |||||
| |||||
|
|
In comp.lang.javascript message <4IidnY9-v9gXG-faRVn_vwA (AT) giganews (DOT) com>, Tue, 1 Jan 2008 13:30:25, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted: 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) } ... or with .split("/") - but why last Index? |
|
If that string is supplied from outside, then the case is already covered as "not known at run time". Return. |
|
Otherwise, no : it is not a good use of eval. Evidently the argument 'fraction' is intended to be a string. But a string is not a good way of representing a fraction internally. |
|
A rational fraction should be represented as {Num:n; Den:d} or similar, or as a case of {Typ:F; Num:n; Den:d}, or as a simple case of a structure designed to hold general expressions (a tree for arithmetic notation; an array or list for RPN). |
|
It is only bad data design that makes the use of 'eval' seem appropriate for that purpose. |
#66
| |||
| |||
|
|
Another reason to minify is that compression (when available) will only reduce comment bulk, whereas minification eliminates it. |
#67
| |||
| |||
|
| Unfortunately, your From and Message-ID headers still violate Internet standard STD11/RFC2822, sections 6.2/3.4 and 4.6.1/3.6.4. Please fix that. |
#68
| |||
| |||
|
|
Anthony Levensalor wrote: David Mark posted : Certainly there are mobile devices (and other agents) using script engines that do not parse try-catch clauses. *A good rule of thumb is to relegate the use of try-catch to scripts that you can afford to lose in such browsers. *In other words, if you have enhancements that will work in virtually any browser (e.g. form validation), don't lump them in with or make them reliant upon scripts that feature try-catch clauses (e.g. Ajax, Flash.) *That way agents that ignore the scripts with try-catch clauses can still make use of the other enhancements. This is an excellent tip, thanks! It's a recipe for disaster. *Whenever you use scripts that use try..catch as-is, compilation will fail with a SyntaxError. *Compilation of the other scripts, that you use along with them and that don't use try..catch, is not guaranteed. *It does not matter at all whether script A uses features that |
#69
| |||
| |||
|
|
John W. Kennedy meinte: Wrong on all counts. You need to find yourself a better dictionary. "Deprecate" means to belittle; "depreciate" means to reduce the value of. The Latin *root* of "deprecate" means to pray to be protected from, but that is not its English meaning, properly or otherwise. ACK. Well, as a non-native speaker I don't have the insights of JWK... I have to rely on dictionaries. That /is/ its English meaning -- its only English meaning until the early 20th century when, as I said, some moron got the two words mixed up. The fact that modern dictionaries perforce have to acknowledge the mistake doesn't change that. So what? Names, meanings, words have changed throughout centuries because of errors in translation or simple typos. Being a percevtive person, you've probably realised that the year is 2008. (You should move to Iceland - their language hasn't changed over the last thousand years. Well, at least only very slightly.) |
#70
| |||
| |||
|
|
In article <477af72e$0$13875$607ed4bc (AT) cv (DOT) net>, "John W. Kennedy" <jwkenne (AT) attglobal (DOT) net> wrote: Doug Miller wrote: In article <477ae913$0$13902$607ed4bc (AT) cv (DOT) net>, "John W. Kennedy" jwkenne (AT) attglobal (DOT) net> wrote: Thomas 'PointedEars' Lahn wrote: a. The word you were looking for is _deprecated_, not "depreciated". Actually, "depreciated" is the correct word. Some moron about 75 years ago decided that "deprecated" sounded more kewl, and got the two words hopelessly confused. Properly, to deprecate something is to pray to be protected from it, ee.g.: Wrong on all counts. You need to find yourself a better dictionary. "Deprecate" means to belittle; "depreciate" means to reduce the value of. The Latin *root* of "deprecate" means to pray to be protected from, but that is not its English meaning, properly or otherwise. That /is/ its English meaning -- No, it's not. It may have been at one time, but that is not its meaning now. |
![]() |
| Thread Tools | |
| Display Modes | |
| |