RFD: How To Recognize Bad Javascript Code

  • Thread starter Jeremy J Starcher
  • Start date
J

John W. Kennedy

Gregor said:
John W. Kennedy meinte:


ACK. Well, as a non-native speaker I don't have the insights of JWK... I
have to rely on dictionaries.


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

I don't complain when someone uses the word "deprecate" to mean
"depreciate", because that battle was lost long ago.

But I /do/ complain when someone insists taking it further, and saying
that /only/ the mistaken use is permissible.
--
John W. Kennedy
"The whole modern world has divided itself into Conservatives and
Progressives. The business of Progressives is to go on making mistakes.
The business of the Conservatives is to prevent the mistakes from being
corrected."
-- G. K. Chesterton
 
J

John W. Kennedy

Doug said:
No, it's not. It may have been at one time, but that is not its meaning now.

....this proves nothing but that your reading is restricted.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
D

David Mark

In comp.lang.javascript message <8331b1ee-5f11-4391-bdc6-05d427912e5f@e2
6g2000hsh.googlegroups.com>, Tue, 1 Jan 2008 16:35:16, David Mark


ISTM wrong always to use something that eliminates all comment, even on
a fully-commercial page not intended to be read.  Comment explaining the
code should be removed; but comment identifying the source and date can
be worth retaining.

Absolutely. I typically add copyright and version information at the
top after minification.
 
D

Doug Miller

....this proves nothing but that your reading is restricted.
It proves, at least, that my reading includes contemporary dictionaries,
whereas yours appears to be limited to those some seven or eight decades old.
The plain fact is that the word does not now have the meaning you insist on
attaching to it. Whether it ever did is irrelevant.
 
J

Jeremy J Starcher

On Wed, 02 Jan 2008 21:08:18 -0600, -Lost wrote:

[ In reference to distribution rights and Dr J R Stockton's warning ]
He is more right than you can possibly imagine.

I've been doing a bit of Googling on that issue. I'm beginning to see.

Thank you for the reference.
Anyway... use something that claims ownership, does not allow
modification, but can be shared wherever or reproduced in its entirety.

I've been looking into that.
Concerning the Function constructor and the with operator -- you said
mention something if anyone feels it is wrong to ignore it...

...it is wrong to ignore it.

<snip>

Seems there have been a few very strong comments in regard to the "with"
operator. I'm beginning to see a pattern.

My biggest reason for not wanting to include it is that I haven't seen it
used very often, it seemed a rarer kind of bad code. I'm starting to
think it might be worth mentioning.
Good luck. I think an "avoid these mistakes" article is 100x better
than a "best practices" for a beginner anyway.

Glad to hear someone agree with me in a "thus stated" kind of way.

My plans for updating the document tonight got pushed aside, thanks to
work related issues.
 
J

Jeremy J Starcher

I'm just heading down that "re-learning everything I thought I knew"
path in Javascript because of that and sites like it. Thanks for not
wanting anyone else to go through this, it's not fun.

Just talk everyone into sending me $US10.00 and I'll start writing a good
book/website. That way, we can put sites like that out of business.

Who knows, maybe take one of those sites and match it script for
script. :)
 
J

Jeremy J Starcher

If it is going into a "Bad Code" document then shouldn't you endeavor to
show the best possible way to do it? And that is why I said that I
thought that a Best Practices document is a better way to go than a Bad
Practices document. The Best document can have an end to it, the Bad
document can never ever cover all the bad code you might (and probably
will) encounter on the web.

Its not my goal to show every single thing that can make for bad code,
but I do believe that there are a /small/ and /limited/ number of things
that truly awful code will have in common.

When I am trying to find a code snippet that will do something I need,
the *first* thing I do is search for the variable "isIE". If not found,
I eyeball the code for any of the things I mention here. If I find any
of these coding 'features' I skip that code and move onto the next one.

While I may end up with code that is less efficient than "the best
possible code," I believe that these simple things narrow down my
choices. As a Javascript novice, I would have found a 'Best Practices'
article too much -- well, at least the "Best Practices" I'd end up
writing.

(Good grief, can you /imagine/ the discussion about what "best practices"
would be like? I doubt we could even agree on a brace style, though K&R
did show the only way. *weg*)

On a more serious note, I've thought about a 'Best Practices' type of
document. I'd say things like:

All variables declarations should be before any code. This reminds the
coder that { code blocks } do not have their own scope. Seems a lot of
people like lazy/delayed declaration. Declare it when you need it.

The discussion would be ... entertaining. And I wouldn't even *really*
be trolling.
 
D

David Mark

Its not my goal to show every single thing that can make for bad code,
but I do believe that there are a /small/ and /limited/ number of things
that truly awful code will have in common.

When I am trying to find a code snippet that will do something I need,
the *first* thing I do is search for the variable "isIE".   If not found,

Similarly, any hits for "userAgent" indicate that the code can be
dismissed out of hand.
 
G

Gregor Kofler

John W. Kennedy meinte:
I don't complain when someone uses the word "deprecate" to mean
"depreciate", because that battle was lost long ago.

But I /do/ complain when someone insists taking it further, and saying
that /only/ the mistaken use is permissible.

It is. According to all my dictionaries (online and printed),
"deprecate" and "depreciate" have different meanings (the latter one is
only used in financial contexts). Webpages tend to have a worldwide
readership and are not restricted to a small circle of linguists, and
it's wise to stick to the proper contemporary meaning of words.

Gregor
 
S

sigvaldi

John W. Kennedy meinte:


ACK. Well, as a non-native speaker I don't have the insights of JWK... I
have to rely on dictionaries.


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

Icelandic has changed a lot in the last 1000 years, but it has not
lost the similarities to the language as it was 1000 years ago. That
means Icelanders are able to read the Saga litterature while still
having the ability to write about the newest technological advances in
their own language without having to borrow words from other languages.
 
G

Gregor Kofler

sigvaldi meinte:
Icelandic has changed a lot in the last 1000 years, but it has not
lost the similarities to the language as it was 1000 years ago. That
means Icelanders are able to read the Saga litterature while still
having the ability to write about the newest technological advances in
their own language without having to borrow words from other languages.

Of course you're right.

Hmmm, the thread started with a page about bad JS, and now we've ended
up about the changes in Icelandic over the last 1000 years - that's one
of the really nice things of usenet.

Gregor
(It was pretty interesting to learn about "tölva" and the like...)
 
E

Evertjan.

Gregor Kofler wrote on 03 jan 2008 in comp.lang.javascript:
It is. According to all my dictionaries (online and printed),
"deprecate" and "depreciate" have different meanings (the latter one is
only used in financial contexts).

Indeed:

deprecate verb (deprecated, deprecating)

to express disapproval of something;
to deplore something.

ETYMOLOGY: 17c, originally meaning 'to pray against evil':
from Latin deprecari 'to try to avert'.

DE 'un' + PRECOR 'to pray, to ask'

=============

depreciate verb (depreciated, depreciating)

1 to fall, or make something fall, in value.

2 to be contemptuous of the worth of something;
to belittle someone or something.

ETYMOLOGY: 15c: from Latin depretiare 'to lower the price of'.

DE 'un' + PRETIUM 'price'
Webpages tend to have a worldwide
readership and are not restricted to a small circle of linguists, and
it's wise to stick to the proper contemporary meaning of words.

Far more important is that the words are different, have a differnt
meaning, and stem from different Latin root words.

Your 'small circle of linguists' has the responsability to advice the
correct and logical use of words, especially in the strict sense of
definitions like Javascript specs.

This is certainly NOT off topic in this NG.
 
J

John G Harris

a) not every line should be ended with a semicolon but every *statement*;
<snip>

That last bit is untrue. I'm surprised that someone who often quotes
ECMA 262 should misunderstand statements so badly.

In fact there are three ways statements can end ...

1 They can end with a nested, smaller, statement.
E.g. if statements and while statements.

2 They can end with a close curly bracket, }.
E.g. block statements {...}, and switch statements.

3 They can end with a semicolon.
E.g. do-while statements, expression statements.

John
 
T

Tim Streater

Randy Webb said:
Evertjan. said the following on 3/1/2008 7:33 AM:



You don't think that the meaning of words, and the history of the
meanings, is off-topic here? Sounds more like it would be better in a
group dedicated to the meanings and history of words.

I didn't see the posts that led to the above, but if the use of the word
'deprecate' is appropriate in this NG, as would seem very likely, then a
brief discussion which might avoid the incorrect use of a similar
sounding or looking word is relevant here.
 
T

Thomas 'PointedEars' Lahn

John said:
Actually, "depreciated" is the correct word.

For all intents and purposes, "depreciated" means a different thing as
"deprecated". The word "deprecated" was suggested by choice, as that is the
word for "not recommended" and "next to obsolete" used in Web standards.
And that is a meaning that not only applies to the given example of bad
style but is also widely understood, no matter the actual etymology. But
even the common dictionaries contradict you. However, you of all people
should know that a language is developing as the society that created it is
developing. To insist on the use or not-use of a word because of its
etymology is denying that.
Some moron about 75 years ago decided that "deprecated" sounded more kewl,

I seriously doubt that because AFAIK the word "cool" did not gain the
meaning of "fashionable/hip" before the 1950s (with Cool Jazz), and the
spelling "kewl" did not come up before the 1990s.

Besides, I really don't care about this person nor about your appreciation
(or rather the lack thereof) of their doing. We are discussing programming
here.


PointedEars
 
J

Jeremy J Starcher

Jeremy J Starcher said the following on 1/2/2008 11:21 PM:
A search for navigator is a better search to use. If a different
variable name is used then you miss it. If you search for navigator you
will find where it is used or defined.

Should be used in combination, since I GoogleCode provided these "gems"
in on the search of "lang:javascript isie"

var IsIE = (document.all)
var isIE=(window.ActiveXObject)
var isIE = document.createElementNS==null;

/* DOUBLE YECK */
var isIE = navigator.appName == 'Microsoft Internet Explorer' ? 1 : 0;
Have you read Matt's?

Of course.

Since you've stated multiple time you think a 'Best Practices' document
is the way to go, I had assumed you wanted something more comprehensive.
How they do things in C is irrelevant to how you do them in JS :)

As I've been told more than once here lately. JS *did* borrow braces
from C, so we should at least borrow how to USE them too. *evil grin*


Best Practices document discussion? It has already happened here when
Matt wrote his.

<URL:
http://groups.google.com/group/comp.lang.javascript/browse_thread/
thread/c532483403801387/738bf21b7896d015?lnk=gst&q=matt+kruse+best
+practices#>

Now that I've not read ... yet. Will most likely be lunchtime
entertainment.
And no, you won't get three people in this group to agree on much of
anything unless it is a condemnation of anything a particular poster has
to say about Javascript. The last time the name was mentioned it got
changed out with ** to mask the name.

Ah.. usenet. Somethings never change.
We couldn't agree on a lot in Unix shell scripting either.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Dr J R Stockton said the following on 1/2/2008 7:14 AM:

Define "supplied from outside".

See FAQ 4.40.
The string is supplied as the value of a select element.

If that's the displayed value, it is essentially outside.
If that value is to be sent to a server, it is headed for outside.
Otherwise, a string is not a good representation; just a simple-minded
one. I should of course have written "from/to outside".
It is when it is the value of a select element.

That is designed for external use, and does not make it a good internal
representation.

Analogy : numbers are always I/O as strings, but internally represented
as Doubles. Having internal Doubles was a language design choice. The
language would have been much better for idiot coders, but slower to run
and much worse for implementors, if numbers were held internally as
full-accuracy decimal strings.
Or a simple string. KISS.

Things should be as simple as is efficient, but no simpler. It's better
to be right than to be simple.

Analogy : the initial choice of getYear() giving a value in 0..99.
Given that the internal workings must handle more than one century, it
would have been no harder for the implementors to have given the full
year. Coders wanting 0..99 would have merely needed to use %100 (and
would have been reminded of Y2k thereby); coders wanting the proper year
would have been saved much inconvenience.

That's been compounded by an idiotic choice, for getYear outside years
1900-1999, of returning the full year (ISO16262 calls for, and Opera &
Firefox give, Year-1900 always).

It isn't bad data design at all. When you need a number in two forms -
both decimal and fraction - and you choose which one to use where, the
best way is to keep the fraction as a string and convert it to decimal
when needed.

Wrong, unless the amount of decimal is very small. A rational fraction
is an ordered pair of numbers (as a complex number is), and should be
held as such.

But remember : my aim is not to make you understand, but to give
everyone else no reason to be deceived.
 
J

John G Harris

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

And awful used to mean awe-inspiring.

More to the point, 'deprecated' is the word to be used in ISO standards
where it has a specific meaning regardless of dictionaries, as in

"These are deprecated features, where deprecated is defined as:
Normative for the current edition of the Standard, but not guaranteed to
be part of the Standard in future revisions."
[copied from the C++ standard]

(Normative means defined by this standard).

From all fornycacion and all deadly synne, and from all the deceiptes
of the worlde, the fleshe, and the devill:

Good lorde deliver us.
<snip>

.... but not yet.


John
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected].
136>, Wed, 2 Jan 2008 21:08:18, -Lost <[email protected]>
posted:

He is more right than you can possibly imagine.


Has "Merlyn" grown so expansive that the doctor must now direct
people to Google rather than citing a precise URL?

You seem to have missed the point : I was not intending to incite people
to read the content, merely to see where on the Web it can be found.

Anyway... use something that claims ownership, does not allow
modification, but can be shared wherever or reproduced in its
entirety.

No; that authorises the keeping of stale copies, which is undesirable.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
John isn't the best person at simply stating what he means.

Don't blame another for your inability to read my mother tongue in an
intelligent manner.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top