Javascript Best Practices Document v1.0

M

Matt Kruse

Richard said:
It isn't debated that much, the only people who seem to argue in
favour of libraries are individuals who have libraries to promote.

It makes sense that if you favor an approach to development, that you would
have something to offer which takes that approach. Much the same way that
you 'promote' closures and offer documentation and example scripts using the
approach.
When we have the
debate the majority of expressed opinion has always been against the
use of monolithic generalised libraries as an inappropriate concept
in browser scripting.

Few would argue in favor of 'monolithic' generalised libraries. Libs with a
specific purpose and just a little extra 'code bloat' as some might call it
is a different story entirely. You often confuse the two.
Here
you are arguing for expedience, but "best practice" most definitely
is about ideals that should be aspired to and not short term
expedience.

The two goals are not mutually exclusive. A developer may need a short-term
solution, yet be interested in learning to do things the 'right' way
long-term.
So a developer who either could not write the code they had undertaken
to create, or could not accurately/effectively schedule their tasks
gets to conceal their incompetence form their employer while reducing
the viability (and so potential profitability) of whatever they have
created?

Ridiculous statement.
I've used many 3rd-party Java libraries which I certainly would not be able
to develop on my own. Yet I benefitted by being able to deliver more
advanced functionality in a shorter timeline.

You seem to argue in favor of writing everything of scratch, which is
absurd. You surely don't follow that reasoning yourself. You just define it
differently to suit your needs.
So your public support for libraries in general, and repeated
promotion of your own libraries, is not without some financial
motivation, and direct returns?

I do not 'promote' my libraries. I offer them as solutions to specific cases
in this group where my already-developed solution matches exactly what the
poster needs. There is no financial motivation. There may be some financial
reward, but it is certainly not a motivating factor.
Anyway, to the "best practices" page; What I like to see when someone
proposes something as a "best practice" is an explanation of why it
might be considered a best Practice.

This is a valid thought, and I had considered adding a "Why?" link which
would open up a pre-hidden DIV explaining in a little more detail the
rationale behind the recommendation.
Your page makes no justifications for the items it proposes as "best
practice" and so is reduced to a sequence of personal assertions.

As is any recommendation. Having a detailed justification doesn't make it
any more 'correct', and readers are still open to disagree with the
justification. Any 'truth' is only as good as your faith in the person
telling it to you. But philosophy is not really on topic...
For example, you propose
that people use bracket notation, seemingly to the exclusion of dot
notation (insane as that would be).

For any developer who doesn't know enough to decide for themselves to do
differently, I think it is the 'safest' recommendation. It will certainly
lead to fewer problems and less confusion for the average web developer.
On the whole your page is too superficial to justify its title

On the contrary, I've received great feedback so far from many others who
said they immediately benefitted from it.
Javascript is a mystery to many. A short, concise, easy to understand
document such as thing can be very valuable to those who may be experienced
programmers but just want a push in the right direction when it comes to
javascript. The FAQ is great, but it's too big, too long, and too bloated to
be scanned quickly in a lunch break by someone who wants to avoid typical
day-to-day JS problems.

For one who criticizes so much, I would expect to see your alternative 'Best
Practices' document offered on the web somewhere. It is conspicuously
absent.
 
M

Matt Kruse

Gérard Talbot said:
It wouldn't take a lot more typing to correct this. Writing valid
markup code shouldn't be a luxury in your document. Just consider
what your document aspires to present: javascript best practices.

I've updated a few places pointed out to be more 'correct', fwiw.
WCAG groups and J. Nielsen have already written on this whole issue.
A script triggered by an onclick event handler in a link should not
do a lot more than a plain vanilla link does otherwise you're not
using a link for its intended purpose to begin with.

So?

1) Using things for their intended purpose leads to less innovation. The web
wouldn't be where it is at now if people only used things for their
'intended purpose'.

2) Links are often preferred for triggering javascript functionality because
of design issues. For example, a DIV showing a list of matches to a
partially-filled input box may be <a> links which trigger a function to
populate the box. Having them as buttons would be ridiculous. And sometimes,
links just look and behave better.

3) J. Nielsen is not god. I think he's right on many points, and
ridiculously wrong on many points. I lose no sleep when he disagrees with
me.
 
R

Randy Webb

Gérard Talbot said the following on 10/12/2005 7:52 PM:
Matt Kruse a écrit :




WCAG groups and J. Nielsen have already written on this whole issue.
A script triggered by an onclick event handler in a link should not do a
lot more than a plain vanilla link does otherwise you're not using a
link for its intended purpose to begin with. In such case, you may be
misusing the <a> element; a <button type="button"
onclick="doSomething();"> would most likely be better markup usage,
better semantic.

And is totally useless with JS disabled.......
 
R

Randy Webb

Dr John Stockton said the following on 10/12/2005 4:59 PM:
JRS: In article <[email protected]>, dated Tue, 11 Oct
2005 23:15:34, seen in Randy Webb



Which in the majority of cases is totally unimportant. Since the aim is
to change the information presented to the mind of the user, the time
taken is usually significant only if it exceeds about 200 ms.

Then why is it that with this code:

var s="10";
var t="12";
var total = Number(s) + Number(t);
alert(total);

That you are one of the first ones to point out:

"Don't convert Strings to Numbers that way, use the unary + because its
*faster*"

Either its speed or its "good enough". Whats the standard?
My Holidays page computes and writes a whole annual holidays table
(about 1.5 windows high) covering 6 years, using DynWrite, in a
perceptible fraction of a second, on a 300 MHz PII. That's good enough.

And if you writing an entire holidays table then you are writing HTML
and not text so your comparison is irrelevant.

But that aside, the standard I have for myself is not to be "good
enough", it's to be the best that I can.
 
R

Randy Webb

Matt Kruse said the following on 10/12/2005 11:07 PM:
The FAQ is great, but it's too big, too long, and too bloated to
be scanned quickly in a lunch break by someone who wants to avoid typical
day-to-day JS problems.

Ditto. It's becoming an "FAQ Book", not an FAQ document. Maximized at
1280x1024, it is somewhere around 20 pages long. I am scared to see how
many pages long it is at 800x600 or so.
 
R

Randy Webb

Matt Kruse said the following on 10/12/2005 10:36 AM:
Randy said:


I've corrected a few of the things you've suggested. Thanks!

Sure thing. Maybe some day when I get around to creating a good test
page, you can test one of my day dream creations.
The use of "libraries" will always be a debate among regulars of this group.

They have advantages and disadvantages. The best you and I can do is
agree to disagree on them. To each his own, ya know?
 
R

Richard Cornford

Matt said:
It makes sense that if you favor an approach to development,
that you would have something to offer which takes that
approach.

"Something to offer" is a bit of a loaded term.
Much the same way that you 'promote' closures and offer
documentation and example scripts using the approach.

I do not "offer" anything. I have written and published explanations of
closures and example of their application. I have also written
extensively on my approach to browser scripting, and published numerous
specific examples. If you have not seen them then that is probably
because you have not been looking.
Few would argue in favor of 'monolithic' generalised
libraries.

Few here would, but they are argued in favour of.
Libs with a specific purpose and just a little extra
'code bloat' as some might call it is a different story
entirely.

What you characterise as a "little extra" code bloat is not necessarily
that little. Every time one of your libraries satisfies a demand for a
less common facility you increase the download for everyone who has no
use or interest in that facility. Every time you need to do something
you must do it in the most general way available, while many actual
applications may preclude much of what the general code must take into
account. Allowing simpler, faster, more specific code to be used in its
place, if that general approach was not lost in the depths of an
interdependent library file. And every time more than one library is
used the odds are good that entire chunks of more or less identical
functionality are being reproduced in each one.

So they are not entirely different stories. Your strategy is a reduction
of a significant problem that is present in monolithic generalised
libraries, but only a small reduction offering diminishing returns as
more of your libraries are used together.

A layered approach to code re-use where systems are built upon many low
level components providing small sets of facilities to all the higher
layers in the system allows the minimisation of redundant code in any
application, and allows the choosing of components that provide those
facilities in a way that closely matches the context in which they are
used, removing the overheads of being general in the face of the
specific. Thus providing the benefits of code re-use for efficient
software authoring but avoiding the bloat and overheads inherent in high
level self-contained general libraries.
You often confuse the two.

The two are not sufficiently different to justify the distinction in
many cases. If you propose that the reduction in code bloat achieved by
moving form monolithic generalised libraries to task specific libraries
is an important difference then the fact that the remaining inherent
code bloat can largely be removed by adopting a third strategy makes
drawing a distinction between the two less effective strategies
superfluous.
The two goals are not mutually exclusive.

But short-term expedience is not a justification for a particular
practice as a "Best Practice".
A developer may need a short-term solution, yet be interested
in learning to do things the 'right' way long-term.

Or, more likely, recognise a best practice but see expedience as a
reason for not employing it in a specific context.
Ridiculous statement.
I've used many 3rd-party Java libraries which I
certainly would not be able to develop on my own.

And Java is a language where the use of libraries is fundamental to the
language's design.
Yet I benefitted by being able to deliver more
advanced functionality in a shorter timeline.

And the relevance of Java authoring to browser scripting is?
You seem to argue in favor of writing everything of scratch,

You know that I don't.
which is absurd.

As it would be, if true.
You surely don't follow that reasoning yourself. You just
define it differently to suit your needs.


I do not 'promote' my libraries.

Oh yes you do. Look at the domain names you have purchased and tell me
you are not in the business of promoting your scripts.
I offer them as solutions to specific cases in this group
where my already-developed solution matches exactly what
the poster needs.

If that was actually true your activities would not have attracted any
comment. You frequently propose the use of your scripts without any
indication that the OP is working in the restricted contexts in which
many of them are appropriate, or any indication that the OP is capable
of doing the extra work necessary to deploy them in a reliable way in
the default Internet context (and given the attitude towards "average
web developers" expressed below it appears that your assumption would be
that they were incapable of undertaking that extra work).
There is no financial motivation. There may be some
financial reward, but it is certainly not a motivating
factor.

Ira Baxter also maintains that it is not the financial return that
leaves her promoting her obfuscator in the face of the reasoned
arguments for its futility. It looks like behaviour that can only be
explained by a vested interest or mental illness.

Without a vested interest my expectation would be that individuals would
be interested in identifying the best possible approaches towards
achieving their goals. And willing to engage in, and be swayed by,
reasoned debate about the possible approaches, even to experiment with
the possibilities to better assess their relative merits. So
encountering persistent intransigence suggests questioning its
motivation.
This is a valid thought, and I had considered adding a
"Why?" link which would open up a pre-hidden DIV explaining
in a little more detail the rationale behind the
recommendation.

That seems a needlessly complicated approach to presenting necessary
information, but let us know when it is done as it is the rational
behind a recommendation that is necessary in assessing its worth.
As is any recommendation. Having a detailed justification
doesn't make it any more 'correct', and readers are still
open to disagree with the justification.

The point of providing a justification for any recommendation is
precisely so that the reader can disagree with the recommendation. Any
proposed "Best Practice" that has a flawed or hollow justification is
unlikely to actually be a "Best Practice". You need to know why
something is being proposed in order to see what it is that makes it a
"Best Practice". And is something really is a "Best Practice" there
should be a really good reason for that being the case.
Any 'truth' is only as good as your faith in
the person telling it to you.

Truth is based entirely on an appeal to authority? You cannot really
believe that?
But philosophy is not really on topic...

Epistemology is entirely relevant to the question of identifying "Best
Practice" form a set of proposed "Best Practices".
For any developer who doesn't know enough to decide for
themselves to do differently,

A "developer who doesn't know enough to decide for themselves" which
type of property accessor to use in any given context? A vision of web
development as a bunch of headless chickens careering about in the dark
continuously bumping into each other and bouncing off walls. The pity is
that that does appear to describe the reality in some organisations, but
it does no good to be pandering to the notion that this would be an
acceptable situation.
I think it is the 'safest' recommendation.

So your are proposing that bracket notation should be used to the
exclusion of dot notation (and proposing it as a "best practice")? Such
a proposal is insane. Bracket notation is slower than dot notation
because of the additional requirement to evaluate the expression within
the brackets and type-convert the result to a string. It should be the
less used property accessor, with bracket notation being used where it
is necessary, and possibly where it contributes to source code clarity
(such as in differentiating between names originating in the HTML and
the javascript).
It will certainly lead to fewer problems and less
confusion for the average web developer.

Only if the "average web developer" really is a headless chicken. The
very worst web developers may well be that incapable of understanding
what they are doing, but for the majority the real solution to not
knowing enough to "decide for themselves" is to provide the explanation
that would facilitate informed decision making.
On the contrary, I've received great feedback so far from
many others who said they immediately benefitted from it.

Marvellous, you demonstrate utter contempt for the intellectual
potential of the "average web developer" and then cite their opinion as
in some way significant to an assessment of your page.
Javascript is a mystery to many. A short, concise, easy
to understand document such as thing can be very valuable
to those who may be experienced programmers but just want
a push in the right direction when it comes to javascript.

And a short concise easy to understand document can also do significant
harm, depending on its contents. Being short is not of itself a good
thing, when the result can be too superficial to promote understanding.
But then if you start form the presupposition that the average web
developer is incapable of achieving a technical understanding of what
they are doing omitting all technical explanation may seem more
justified than its inclusion.
The FAQ is great, but it's too big, too long, and too
bloated to be scanned quickly in a lunch break by
someone who wants to avoid typical day-to-day JS problems.

This group's FAQ is quite big, and all the pressure is to make it
bigger. It never was designed to be read in a lunch break. But then you
cannot learn javascript in a lunch break, or 24 hours, or a couple of
weeks, and expecting to be able to do so is totally unrealistic.
For one who criticizes so much, I would expect to see your
alternative 'Best Practices' document offered on the web
somewhere. It is conspicuously absent.

You see a superficial document as appropriate in addressing the question
of "Best Practice", I don't. Late last year I was involved in the
process of creating a javascript authoring standards document for the
software house for which I work. The intention was to lay down formal
rules and "Best Practices" to be followed by our sub-contractors in
creating javascript (but inevitably, once formalised, those same rules
would also have to be followed internally). The resulting document is 50
sides of A4 and does no more than lay down rules that will be followed.
The criteria for choosing those rules, the reasoning behind them, the
arguments about them and the decision making that resolved those
arguments are not part of that document. They were the subject of
discussion in various meetings and extensive e-mail conversations, and
then only when a specific "Best Practice" was subject to disagreement
(as most were adopted without opposition or debate).

I think that a document about "best Practices" should be about best
practices, rather than a list of practices that one individual believes
to be "best Practices". So such a document has to include the
explanations/justifications that allow the reader to understand why a
practice is being proposed, what benefits are expected to follow from
its adoption, and how its adoption is likely to impact upon other
aspects of the scripting task. And for me such a document should include
practices that are argued as best practices but with which I personally
disagree, along with their justifications. The result should be a
document that allowed reader to cherry-pick the set of "best practices"
that best suited their authoring context, and do so on the basis of
informed decision making.

The result is not a screen full of text, it is probably about the size
of a largish chapter in a book. So is it surprising that I have not
created such a document, given the amount of work involved?

That is a fundamental difference between us. I will not be satisfied to
publish anything less than a document that allows its readers to make
informed decisions about the adoption of best practices (and so also
make informed decisions about when it might be expedient to disregarded
them), and you see your best interests in pandering to a flock of
headless chickens.

Richard.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 12 Oct 2005
19:30:42, seen in Gérard Talbot
Matt K. explicitly states that numeric indices is a bad practice.
"Referencing forms using indexes, such as document.forms[0] is bad
practice."

If he wrote only that about it, he's wrong, through not giving the
possibilities adequate consideration.

Using fixed numeric indices to refer to what could be a named form is
indeed bad, since the page might get edited into another order. If a
page clearly will only ever have a single form, the practice is
harmless.

If one must iterate through all forms, then sing varying numeric indices
is reasonable, perhaps inevitable.

And if for some unaccountable reason one were to need to refer, say, to
the form which comes third, even after possible rearrangement, then a
fixed index would be appropriate.


[The parseInt function is] overkill in most cases. The value should
have been validated already, so all that's necessary is to convert
the value which the unary plus operator does very well.


I don't agree with you. parseInt function original purpose (specific
purpose, defined task) is to parse a string and convert it into
integers.


If the string has been validated as a number, which it should have been,
then the only operation that is needed is conversion. The sole purpose
of the unary plus operator is to convert its operand to a number. The
parseInt function, on the other hand, parses only to an integer -
totally different and often not as useful.

Ok, what about parseFloat() then? I mentioned it in my original post.
No. Matt describes string to number conversion, not string to integer.



The addition operator and the plus (+) symbol itself is overloaded. The
unary plus operator is not. That the latter isn't a function is utterly
irrelevant.

IMO, tricks based on + and -0 can not be the best recommendable way to
convert a string to a number. parseInt or parseFloat should be used instead.

Then you are wrong; and sentences should start with a capital letter.
One example: Javascript Bible 4th edition by D. Goodman on "Converting
strings to numbers" p.78-79. Not one word on + and - tricks: everything
in his words clearly refers to the use of parseInt and of parseFloat. Is
he way off the fact and the matter?

Yes, but the book does date from before the matter was (possibly first)
raised here.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 13
Oct 2005 00:52:31, seen in Richard Cornford
Matt Kruse wrote:

It isn't debated that much, the only people who seem to argue in favour
of libraries are individuals who have libraries to promote. It seems
that the vested interest and unwillingness to abandon the time already
invested tends to encourage intransigence. When we have the debate the
majority of expressed opinion has always been against the use of
monolithic generalised libraries as an inappropriate concept in browser
scripting.


One should, however, distinguish in debate between at least two distinct
forms of bloat javascript bloat.

(0) Writing multiply-repeated code, for example to add a leading zero or
to check that a field is non-empty, when it would be perfectly simple to
write a function (or method) to be called multiple times.

(1) Putting a large number of perhaps well-written functions in a single
include file, so that all readers of any page that uses any of the
functions must fetch the whole lot.

(2) Writing and using a single large function to do many varieties of
one thing, perhaps controlled by parameters, when only one variety will
be used at any given time, but the whole must be loaded. Example, a
function to read and validate a date in various field orders, possibly
with suffices, possibly with months in letters, in various languages,
possibly with roman numerals. Writing it as an exercise is harmless;
deployment in full is generally wasteful.


It is perverse to state this in the context of a request for comments on
a document that asserts that its subject is "best Practices". Here you
are arguing for expedience, but "best practice" most definitely is about
ideals that should be aspired to and not short term expedience.

You think that, Richard : but then you're not a Merkin. Perhaps the
document should be called "Javascript for dummies", though IIRC that
title has already been taken.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 12 Oct
2005 23:33:07, seen in Randy Webb
Dr John Stockton said the following on 10/12/2005 4:59 PM:


Then why is it that with this code:

var s="10";
var t="12";
var total = Number(s) + Number(t);
alert(total);

That you are one of the first ones to point out:

"Don't convert Strings to Numbers that way, use the unary + because its
*faster*"


The apparently quoted sentence is making a general statement about
string-to-number conversion, prompted (you say) by the code above; it
makes no claim that the particular example would execute perceptibly
faster.

For string-to-number, unary + has several advantages. It's faster to
type and faster to download, being briefer. It never treats a pure
decimal digit string as other than decimal; no concern about forgetting
the parameter 10.

And it's possible to use it in a loop that takes longer than user
reaction time, so that a gain in speed is not useless.


Either its speed or its "good enough". Whats the standard?


And if you writing an entire holidays table then you are writing HTML
and not text so your comparison is irrelevant.

Writing and executing HTML will take at least as long as writing and
displaying a similar amount of plain text. Therefore if HTML is not too
slow, plain text will not be.

So I tested with plain text; DynWrite took under 100 ms to write 15000
characters (in eval(), too). That's well over a screenful. So my point
is mow better demonstrated.


But that aside, the standard I have for myself is not to be "good
enough", it's to be the best that I can.

Then why are your criticisms nowadays always so ill-judged? ... must be
the best that you can do.
 
M

Matt Kruse

Richard said:

Richard, your posts are too verbose to be responded to in detail, and we've
disagreed on this before. As I've said before, you're an intelligent guy and
you do good stuff, but your perspective is very different from mine. Your
experience with Javascript is not the norm. In my experience with many web
developers, Javascript is this piece-of-crap scripting language that they
have to deal with and struggle with. It gets in the way of what they want to
do, but they have to use it. Many have no interest in learning the language
or its quirks, nor do they want to spend hours learning best practices of
FAQs.

My approach is to cater to those people and others who have no interest in
becoming javascript experts. I realize and accept that they will not read
the FAQ or a book on the topic, nor will they experiment with browser quirks
or other js-related topics. The question is, if you're working with these
people, do you continue to let them make common easily-corrected mistakes,
or do you identify the "low hanging fruit" and help them fix the most common
problems quickly and easily, so you can at least get some immediate benefit?
Do you tell them to 'write their own' calendar popups and tree structures
because they need to know the inner-workings, only to see that their end
result is horrible and goes into production because of the deadline? Or do
you offer a generalized library that might have some 'bloat' but
accomplishes the task way better than they would have written themselves?

Not everyone wants to be a javascript expert. You do. That's nice. But don't
pigeon-hole everyone into your mindset.
What you characterise as a "little extra" code bloat is not
necessarily that little. Every time one of your libraries satisfies a
demand for a less common facility you increase the download for
everyone who has no use or interest in that facility.

The point is - who cares? If it's an extra 5k or even 10k, that is often way
over-shadowed by graphics sizes, flash, etc.
If your goal is to create tight, compact pages, then fine - don't use libs.
But that is _NOT_ a requirement for most people.
The convenience of using a lib with a little code bloat is more important
than the extra few k of text that is downloaded.
And
every time more than one library is used the odds are good that
entire chunks of more or less identical functionality are being
reproduced in each one.

Not if used correctly.
And the relevance of Java authoring to browser scripting is?

Same concept, different language/environment.
Develop a solution to a general problem and package it up with an interface.
People can then use your solution to the problem in their work, even if your
solution contains much more functionality than they actually need.
Without a vested interest my expectation would be that individuals
would be interested in identifying the best possible approaches
towards achieving their goals. And willing to engage in, and be
swayed by, reasoned debate about the possible approaches, even to
experiment with the possibilities to better assess their relative
merits.

I'd say that I definitely fall into that categorization.
The point of providing a justification for any recommendation is
precisely so that the reader can disagree with the recommendation.

The target audience for my recommendations (which should be clear by the
content) are generally people who may not even have enough knowledge to
decide for themselves whether the justification is reasonable or not. Or
they may not even care. They just want their stuff to work.
A "developer who doesn't know enough to decide for themselves" which
type of property accessor to use in any given context? A vision of web
development as a bunch of headless chickens careering about in the
dark continuously bumping into each other and bouncing off walls. The
pity is that that does appear to describe the reality in some
organisations, but it does no good to be pandering to the notion that
this would be an acceptable situation.

It describes the reality in _many_ organizations, and _many_ individuals.
You don't see regularly how many people _DESPISE_ javascript?
I see absolutely horrible javascript practices so often that even suggesting
the most basic of 'best practices' would add value to many people. And that
is my goal.
Marvellous, you demonstrate utter contempt for the intellectual
potential of the "average web developer" and then cite their opinion
as in some way significant to an assessment of your page.

No, my point is, there are many who have a very basic understanding of
javascript, and a document like this is short, practical, and adds immediate
value to their development.
But then
you cannot learn javascript in a lunch break, or 24 hours, or a
couple of weeks, and expecting to be able to do so is totally
unrealistic.

And yet your expectation is that every web developer in the world should
devote this much time to learning it and using it correctly.
That expectation is highly absurd.
My point is, people don't have to invest that much time to do many of the
tasks which they want to accomplish. If all they want is a date picker on
their page, they can have one in 10 minutes. They don't need to spend weeks
learning Javascript to implement one. Yet your 'elitist' approach would say
they are not worthy of one if they aren't willing to invest the time. That's
completely unrealistic.
Late last year I was involved
in the process of creating a javascript authoring standards document
for the software house for which I work.
...
The resulting document is 50 sides of A4 and does no
more than lay down rules that will be followed.

Such a document would be completely worthless to most web developers.
The result is not a screen full of text, it is probably about the size
of a largish chapter in a book. So is it surprising that I have not
created such a document, given the amount of work involved?

There is value in partially solving a problem.
If you can add value in a specific area, even without solving the entire
problem, that is a good thing.
A 'Best Practices' document doesn't need to cover everything. IMO.
That is a fundamental difference between us. I will not be satisfied
to publish anything less than a document that allows its readers to
make informed decisions about the adoption of best practices (and so
also make informed decisions about when it might be expedient to
disregarded them), and you see your best interests in pandering to a
flock of headless chickens.

I'm realistic. You're idealistic.
I'm practical. You're a perfectionist.
I cater to the masses. You cater to those you deem worthy.
I understand the problems of the average developer. You tell them to RTFM.

I prefer my view.
 
R

Randy Webb

Dr John Stockton said the following on 10/13/2005 5:29 PM:
JRS: In article <[email protected]>, dated Wed, 12 Oct
2005 23:33:07, seen in Randy Webb




The apparently quoted sentence is making a general statement about
string-to-number conversion, prompted (you say) by the code above; it
makes no claim that the particular example would execute perceptibly
faster.

Oh geez John, you get worse and worse everyday. Let me find you another
quote that I recall:

<quote>
Once upon a time, you made only intelligent remarks.
</quote>

You are beginning to fit that bill. You can't seem to make up your mind
what practices you want to suggest/follow. It seems to depend on the day
of the week.

Your perception that "innerHTML is good enough" is just plain ignorant
at best.
For string-to-number, unary + has several advantages.

And several disadvantages.

It's faster to type and faster to download, being briefer.

If you type so slow that typing Number takes you that much longer than
typing +, then you don't need to be writing code, you need to be taking
typing lessons.

And, are you really serious about the "faster to download" when it comes
to 5 characters of data?
It never treats a pure decimal digit string as other than decimal;
no concern about forgetting the parameter 10.


I wrote nothing about the parameter 10 which Number does not need. I
used Number for that very specific reason instead of parseInt and
parseFloat.

But, are you saying that Number(k) will treat a pure decimal digit
string as anything other than decimal?
And it's possible to use it in a loop that takes longer than user
reaction time, so that a gain in speed is not useless.

So now you use it for speed but use the slower innerHTML because its
"good enough"?


Main Entry: hyp·o·crite
Pronunciation: 'hi-p&-"krit
Function: noun
Etymology: Middle English ypocrite, from Old French, from Late Latin
hypocrita, from Greek hypokrites actor, hypocrite, from hypokrinesthai
: a person who puts on a false appearance of virtue or religion
- hypocrite adjective
Writing and executing HTML will take at least as long as writing and
displaying a similar amount of plain text. Therefore if HTML is not too
slow, plain text will not be.

The time it takes will be directly proportional to the amount of HTML
that is in the string.
So I tested with plain text; DynWrite took under 100 ms to write 15000
characters (in eval(), too). That's well over a screenful. So my point
is mow better demonstrated.

No, writing plain text using innerHTML will NOT show its speed problems.
Perhaps you should test the DOM2 methods to inject plain text into a
wrapper element. But does your antiquated IE4 support it?
Then why are your criticisms nowadays always so ill-judged? ... must be
the best that you can do.

It probably would be the "best that I can do" if I aspired to be only as
good as you. I have higher goals/standards/expectations than that for
myself - you should consider doing the same. It would help you tremendously.

Now, you can babble all you want. I have better things to do than argue
with you about your ignorance of what you are writing about. Stick to
numbers and dates, they are your strong point. dHTML and the speed of it
is not.
 
J

John G Harris

Dr John Stockton said:
JRS: In article <[email protected]>, dated Wed, 12 Oct 2005
19:30:42, seen in Gérard Talbot
<[email protected]> posted :


Then you are wrong; and sentences should start with a capital letter.
<snip>

Not funny. This newsgroup is read by beginners; we mustn't trick them
into writing ParseInt (with a capital P).

DB is an abbreviation for database.
dB is a ratio.

dBaseII is (was?) a trade mark.
DBaseII is not, or is a different trade mark.

mW powers your torch.
MW melts scrap metal.

John
 
G

Gérard Talbot

Randy Webb a écrit :
Gérard Talbot said the following on 10/12/2005 7:52 PM:



And is totally useless with JS disabled.......

<body onload="document.getElementById('idParg').style.display =
'block';" (...)>
(...)
<p id="idParg" style="display: none;"><button type="button"
onclick="doSomething();">Some caption describing action</button></p>

If JS is enabled, then the button will be visible and usable. If JS is
disabled, the button won't be visible nor usable.

You may even use (toggle) alternate content depending on JS support
depending on what exactly the JS action is supposed to do, should do.
There are many possibities depending on the page goals.
I still insist that a link should be a link, should behave like a link,
should look like a link, etc... Otherwise, it's misusing markup code,
semantic markup code.

Gérard
 
G

Gérard Talbot

Matt Kruse a écrit :
I've updated a few places pointed out to be more 'correct', fwiw.




So?

1) Using things for their intended purpose leads to less innovation.

This is over-exaggerated. This is confusing issues.

The web
wouldn't be where it is at now if people only used things for their
'intended purpose'.

Using tables for page layout is not innovation.
Using dozens of <br> instead of CSS margin-top or margin-bottom is not
innovation.
Using dozens of &nbsp; instead of CSS padding or CSS text-indent is not
innovation.
Using empty <p></p> instead of CSS margin-bottom is not innovation.
Using <blockquote> to indent a section when such text section has
nothing to do with a quote is not innovation. etc..

There are billions of webpages which do just that which make their
webpages bloated, a nightmare tag soup mess impossible to update, slow
to download, etc..
2) Links are often preferred for triggering javascript functionality because
of design issues. For example, a DIV showing a list of matches to a
partially-filled input box may be <a> links which trigger a function to
populate the box. Having them as buttons would be ridiculous. And sometimes,
links just look and behave better.

If the <a> links brings up a new page content into a window, then it
would be adequate usage. I don't know for sure in the example you give
since I do not see, can not examine the example you are referring to.

What I am against is improper use of markup which will inevitably affect
the way conformant user agents will address such markup. It's about
software interoperability.
E.g.: A form submission should be using a button that looks/is/behaves
like a submit button, not a link (<a>). Search engines do not index
submit buttons but they will index links semantically used as links. A
lot of assistive technologies (speech browsers, translation features,
etc.) will try to render as best they can what is semantically coded as
links to begin with.

Regards,

Gérard
 
G

Gérard Talbot

Matt Kruse a écrit :
I've updated a few places pointed out to be more 'correct', fwiw.

This is one of your change:

<form name="myform" action="">
<input type="text" name="val1" value="1">
<input type="text" name="val2" value="2">
</form>

If the document is HTML 4.01 strict, it will still trigger a validation
error while

<form name="myform" action="[url]">
<p><input type="text" name="val1" value="1">
<input type="text" name="val2" value="2"></p>
</form>

will not trigger a validation error.

Gérard
 
M

Michael Winter

On 14/10/2005 21:13, Gérard Talbot wrote:

[snip]
<form name="myform" action="">
<p><input type="text" name="val1" value="1">
<input type="text" name="val2" value="2"></p>
</form>

will not trigger a validation error.


True, but since when have INPUT elements been part of a paragraph? A DIV
or FIELDSET element is more appropriate.

Mike[/QUOTE]
 
M

Matt Kruse

Gérard Talbot said:
<form name="myform" action="">
<p><input type="text" name="val1" value="1">
<input type="text" name="val2" value="2"></p>
</form>
will not trigger a validation error.


I don't see that as a compelling reason to change it.

Validation is a tool, not a goal in itself.[/QUOTE]
 
M

Matt Kruse

Gérard Talbot said:
The web
Using tables for page layout is not innovation.

Oh yeah? Were you around to remember when the <table> tag was introduced by
Netscape? It made page layout *possible*. Although it may not have been its
inteded purpose, it certainly was a huge step in moving the web towards more
where it is today.

Had everyone stuck to the rules that purists have about when to use tables,
the web would have been much uglier for much longer.

I still use tables for layout. Why? Because it works consistently across
browsers, it's much easier to accomplish nice layouts that equivalent CSS
layout, it degrades more consistently than CSS, and it's easier. I don't
care if it's "semantically" wrong. It works. Better than the alternatives in
most cases.

There are many factors that must be taken into consideration when deciding
which approaches to use for the web. Validation is just one of those
factors, and for me it's very low on the list. People who put it at the top
are usually missing the point, IMO.
 
R

Randy Webb

Gérard Talbot said the following on 10/14/2005 3:35 PM:
Randy Webb a écrit :


<body onload="document.getElementById('idParg').style.display =
'block';" (...)>
(...)
<p id="idParg" style="display: none;"><button type="button"
onclick="doSomething();">Some caption describing action</button></p>

If you want a button that is JS dependent, then have JS generate that
button :)

JS generating the button also doesn't require as much feature detection
as the above onload /should/ do but doesn't.
If JS is enabled, then the button will be visible and usable. If JS is
disabled, the button won't be visible nor usable.

If the page error's any time before the onload fires, then the user
doesn't get the button even though scripting is enabled. That same
problem arises with the JS generated button though.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top