Javascript Best Practices Document v1.0

M

Matt Kruse

Thomas said:
No, it certainly does not, and to state such can only be based on
shallow or no insight, and bad examples of the otherwise very viable
alternatives to layout tables.

I disagree.
(And for the record, I've been doing this for 12 years, and I'm quite
informed on the topic.)

A table-based layout renders more consistently across browsers than a
CSS-based layout, in my experience. Except for very basic layouts. With a
table-based layout, I can have my content look mostly the same even in very
old browsers. With CSS-based layout, older browsers see either a very plain
or a broken layout.

I'm very familiar with (although, admittedly not an expert in) CSS-based
designs and layouts. I use CSS extensively myself, and I often use it for
positioning and layout. But some things are very difficult to do
consistently with pure CSS. In many cases, using a CSS approach is _much_
more work than a simple table layout which will work consistently in every
browser you can test in. The reasons for dumping tables in favor of pure CSS
are often unconvincing to me. As soon as a simple 3-column layout becomes
easier and more consistent to do in CSS than with tables, let me know. Until
then, I'll probably stick with a big table for the overall layout and CSS
for the rest. That's just MO.

I love the concept of CSS and CSS-based layouts. Unfortunately, it just
hasn't evolved fully yet. Abusing CSS for page layout is just as bad as
abusing tables for it, IMO. CSS is good for positioning and styling. It's
not so good for layout. And browser support (or lack thereof) certainly
makes it more difficult to use it for layout.
You (and, alas, many others) seem to still perceive the Internet
including the Web as a screen-only medium for non-handicapped people.

I don't perceive things that way at all. I realize the reality of how the
web is accessed and who is using it.
In most cases, I agree that web authors need to consider all these factors.
In some cases, it doesn't matter. And in some cases, it should be the screen
readers and other accessibility devices that should be improved to cater to
the current state of the web.
 
R

Randy Webb

Gérard Talbot said the following on 10/15/2005 4:54 PM:
Randy Webb a écrit :



It's kinda difficult to maintain a long discussion on several sharp
topics while having doSomething() function and long reading to do. IMO,
a full-page example would certainly bring some light, would refresh this
long thread.

That is part of the problem. You are wanting specific examples in light
of a general page. someFunction() can do anything you want. As long as
it returns true/false, what it does (with regards to this thread) is
irrelevant.
With proper server-side scripting.

it



Include statement.


I am not sure how much of the above is a result of your quoting, or, if
it is an intended correction.
in a template document and



No real live webpage example.

Again, you are wanting a specific example to a general question.

But, before *anybody* tries to do a gEBI emulation in IE4 they have to
understand, at a minimum, what the impact is. There are some things that
gEBI does that document.all does differently.
gEBI emulation. No code. No url. No concrete reference.

There is a gEBI emulation in the FAQ in the DynWrite area. The basics of
it came from the metallusions site. But again, you are wanting specific
answers to a general discussion.
 
R

Randy Webb

Thomas 'PointedEars' Lahn said the following on 10/16/2005 5:02 PM:
Matt Kruse wrote:




Rubbish. Your thinking seems to base on a static medium which the Web
certainly is not and has never been.

The web, with it's sites, was *very* static when it began. Simply
because there was no way to make it dynamic.
No, it certainly does not, and to state such can only be based on shallow
or no insight, and bad examples of the otherwise very viable alternatives
to layout tables.

The web browser that is in my cell phone has *NO* support of CSS
positional layout. It does support tables though.

And don't tell me to upgrade it, it is the latest/updated browser
available for it.
 
G

Gérard Talbot

Matt Kruse a écrit :
I disagree.
(And for the record, I've been doing this for 12 years, and I'm quite
informed on the topic.)

A table-based layout renders more consistently across browsers than a
CSS-based layout, in my experience.

If you code with a given lowest common denominator, then for the sake of
this discussion, you should objectivize this info. If you absolutely
want to create roughly the same page layout in NS4, IE4, Opera 8.50 and
Safari 2.01, then a table-based design for your page will meet such
requirements.
But if you code according to web standards and acknowledged web design
principles, then table-based layout shouldn't be used [for non-tabular
data].

Except for very basic layouts. With a
table-based layout, I can have my content look mostly the same even in very
old browsers.

How old is "very old browsers"? To me, IE 4 and NS 4 are very old,
1997-ish browsers, designed and developed in 1996. To me, MSIE 5.01 is a
very old browser too.
To others, MSIE 6 is a very old browser: MSIE 6 beta 1 was released more
than 4½ years ago, you know.

With CSS-based layout, older browsers see either a very plain
or a broken layout.

I'm very familiar with (although, admittedly not an expert in) CSS-based
designs and layouts. I use CSS extensively myself, and I often use it for
positioning and layout. But some things are very difficult to do
consistently with pure CSS.


Consistently. What do you mean with consistently? Do you mean consistent
visual layout across different browsers? Do you mean pixel-perfect
rendering for a webpage designed with pixel-perfect ambitions?
Again, I'm afraid we're talking in general terms, in abstract terms,
regarding non-defined, non-concrete webpage situation.

In many cases, using a CSS approach is _much_
more work than a simple table layout which will work consistently in every
browser you can test in.

"will work consistently in every browser": is that realistic? is that a
sane goal? When you say every browser, you mean MSIE 4, NS 4 or older
than those? Even those who have zero support for CSS?

HTML was never designed to be a layout language. It is perfectly normal
that HTML can be rendered differently in different media, softwares,
etc. and this regardless of CSS support.
As far as accessibility (and accessibility groups, guidelines,
checkpoints, directives, norms, etc..) is concerned, what matters is
that content of a page is/remains accessible and that navigation in a
site is/remains functional. How a webpage will look in a tableless
browser or in a CSS-less browser or.. etc.. is not really the most
important issue: access to content and functional navigation are.

The reasons for dumping tables in favor of pure CSS
are often unconvincing to me.

You don't believe in writing markup code without validation errors in
your website to begin with. You don't believe in using a doctype which
will trigger standards compliant rendering mode in modern browsers to
begin with.
You believe in deprecated markup. And then you want pure CSS to work in
your pages?

As soon as a simple 3-column layout becomes
easier and more consistent to do in CSS than with tables, let me know.

Well, they are available. It all depends on your requirements in terms of
- lowest common denominator browser/requirement,
- how consistent and accurately consistent the layout should be for
browsers like, say, IE4, IE5.x, etc.
- if the 3-column layout must be based on floats and/or abs. pos.,
- if the layout must be fluid or rigid,
- if the layout must be scalable or not,
- if the layout must be controled by js,
- etc...

It all depends on how much constraints, requirements you may have. But I
assure you that a "simple" 3-column layout has been around/available for
many years.

Until
then, I'll probably stick with a big table for the overall layout and CSS
for the rest. That's just MO.

I love the concept of CSS and CSS-based layouts. Unfortunately, it just
hasn't evolved fully yet. Abusing CSS for page layout is just as bad as
abusing tables for it, IMO. CSS is good for positioning and styling. It's
not so good for layout.

Zen Garden: th beauty of CSS design
http://www.csszengarden.com/
Go ahead and send an email to the creators of that site stating that CSS
is "not so good for layout" and you'll get replies for sure.

regards

Gérard
 
M

Matt Kruse

Gérard Talbot said:
If you
absolutely want to create roughly the same page layout in NS4, IE4,
Opera 8.50 and Safari 2.01, then a table-based design for your page
will meet such requirements.

Thank you. That was my point.
You don't believe in writing markup code without validation errors in
your website to begin with.

As I continue to work on the design and content of
www.JavascriptToolbox.com, I am validating it (The url still points to my
old site, but I am trying to get time to put up the new content). I see
value in validating, but if something doesn't validate and I have a reason
for it to be so, I don't mind at all.
You don't believe in using a doctype which
will trigger standards compliant rendering mode in modern browsers to
begin with.

On the contrary, I do. In fact, every page on my new site will have
user-selectable doctype links at the top so that scripts can be tested in
whichever doctype the user happens to be using.
Zen Garden: th beauty of CSS design
http://www.csszengarden.com/
Go ahead and send an email to the creators of that site stating that
CSS is "not so good for layout" and you'll get replies for sure.

If you look at some of the stylesheets created for the site, you quickly
realize that CSS is not good for layout.
 
M

Michael Winter

On 17/10/2005 04:48, Gérard Talbot wrote:

[snip]
http://www.csszengarden.com/
Go ahead and send an email to the creators of that site stating that CSS
is "not so good for layout" and you'll get replies for sure.

CSS Zen Garden is an exhibition of good graphical design (exquisite, in
some cases). It demonstrates that attractive layouts can be achieved
with CSS. However, neither the markup nor many of the sample layouts can
be considered good Web design.

The markup is bloated so that there are plenty of hooks for the
different style sheets (this is even acknowledged in the markup). Many
of the style sheets are inappropriate because they produce inflexible
and potentially fragile designs, as well as exhibiting bad practices
(pixel-defined fonts and text containers, dependency upon background
images, etc.).

The site shows what /can/ be done, but doesn't necessarily demonstrate
/how/ to go about doing it.

Mike
 
G

Gérard Talbot

Matt Kruse a écrit :
Thank you. That was my point.




As I continue to work on the design and content of
www.JavascriptToolbox.com, I am validating it (The url still points to my
old site, but I am trying to get time to put up the new content).

I was referring to your whole site. I was not referring to the
javascript section. I have not find a single page on your whole website
using a strict DTD. Nowhere do I see a doctype decl. in any of your
webpages. So you never trigger standards compliant rendering mode in
modern browsers.

I see
value in validating, but if something doesn't validate and I have a reason
for it to be so, I don't mind at all.

You won't mind validation errors if you do not find compelling reason to
fix these either. Browsers and browser versions don't just consult
*_you_* before rendering a page, you know. Unless you actually test your
webpages with all available browsers and browser versions and web-aware
softwares, you can't just dismiss validation errors on a gut/random
feeling just like that... in particular if layout consistency across
browser is something you highly value.

There is no formal error condition in HTML. That is why it is much more
important to validate the markup code. Furthermore if consistent layout
(as consistent it may be) is a goal in itself for a web developer.
On the contrary, I do.

I have not found a single webpage on your whole website which uses a
doctype triggering web standards compliant rendering mode in modern
browsers. And the thing is that so far you have demonstrated a high
consideration layout consistency across browsers.
I see contradictions in some of your posts on this precise issue.

In fact, every page on my new site will have
user-selectable doctype links at the top so that scripts can be tested in
whichever doctype the user happens to be using.

You said word for word that CSS is not so good for layout. I am quoting
you fair and square here. You somehow "blame" CSS for not producing as
accurate and consistent layout as tables can but
- you want to support old browsers like NS4, IE4 and other browsers
which have buggy and incomplete support for CSS
- it seems you want pixel-accurate layout for every/all browsers
- you have not defined the configuration of your 3 columns layout
"needs" in terms fluid/fixed design, scalability, float vs abs. pos.,
css hacks or no, etc. There are plenty of 3 columns layout available and
free out there.
If you look at some of the stylesheets created for the site, you quickly
realize that CSS is not good for layout.

I don't follow you. I don't understand you at all on this. I thought
your site was
http://www.mattkruse.com/

which starts exactly as follows:

<HTML>
<HEAD>
<TITLE>Matt Kruse's Site</TITLE>
<style>
BODY {
scrollbar-face-color:#006666;
scrollbar-arrow-color:#ffffff;
scrollbar-track-color:#66aaaa;
scrollbar-shadow-color:#006666;
scrollbar-highlight-color:#ffffff;
scrollbar-3dlight-color:#66aaaa;
scrollbar-darkshadow-Color:black;
}
..SPONSOR {
color:#006666;
}
</style>
</HEAD>

<BODY BGCOLOR="#FFFFFF" LINK="#006666" VLINK="#004444">

<center>
<table width=99% border=0 cellpadding=0 cellspacing=0>
(...)

Gérard
 
M

Matt Kruse

Gérard Talbot said:
I was referring to your whole site. I was not referring to the
javascript section. I have not find a single page on your whole
website using a strict DTD. Nowhere do I see a doctype decl. in any
of your webpages.

My personal site is a whole different matter. It's evolved (or in many cases
hasn't changed at all) over the last _TWELVE YEARS_. It is certainly no
representation of my knowledge or skills. It's a personal site, and I don't
care if it validates or looks ugly to some people. I have a family and a
job, and updating my personal web site is certainly a very, very, very low
priority in my life ;)

You're welcome to view the source at http://www.ajaxtoolbox.com/ which does
in fact use a strict doctype and probably looks more like what you'd like to
see.
- you want to support old browsers like NS4, IE4 and other browsers
which have buggy and incomplete support for CSS

If I can with a table layout, but not with a CSS layout, why should I use a
CSS layout?
- it seems you want pixel-accurate layout for every/all browsers

Nope, not at all.
- you have not defined the configuration of your 3 columns layout
"needs" in terms fluid/fixed design, scalability, float vs abs. pos.,
css hacks or no, etc. There are plenty of 3 columns layout available
and free out there.

Take for example the layout at http://www.ajaxtoolbox.com/

If you can duplicate that layout with pure CSS and it:
a) Is simpler to code
b) Is fairly consistent across browsers, even older ones
c) Looks just like what I have

then I'll consider the alternative.
I don't follow you. I don't understand you at all on this. I thought
your site was...

My site has nothing to do with csszengarden. I stated that in order to
ahieve the impressive layouts that you see on _that_ site, you quickly
realize why CSS is not good layout. The resulting code using CSS is often
quite a disaster.

But really, this discussion is *way* off from javascript, and I don't see
what your goal is...
 
R

Richard Cornford

Matt Kruse wrote (2005:10:16):
No one can be an expert in everything.

It is not necessary to be an expert in order to understand browser
scripting.
Rather than considering yourself and your job position, consider
a one-man 'webmaster' for a small company who must run the web
server, the external web site, the internal intranet, code in
HTML and PHP, do some database work, write some javascript,
create some images, etc.

You are describing someone in an extremely responsible position.
Responsible for web site, database and network security (in relation to
external connections/access), responsible for a public face, and
consequent credibility, of the organisation, potentially responsible for
a significant revenue source, etc.

You are also describing someone who does not need to use javascript at
all, it is not compulsory.
Very few people in the real world would be an expert in all
of those areas,

And most of them will realise that they are not qualified to do that job
and so not apply for it.
or have anywhere close to enough time to study each
area in-depth.

In a responsible position, where the potential to do harm exceeds the
individuals wages, not having the skills to do the job effectively is
seriously unprofessional. And in the event of finding ones self
manoeuvred into that position without the skills it is seriously
unprofessional not to make the time to learn the required skills. But
even so, those skills do not necessarily need to include javascript at
all, as a web site can get by without it easily enough.
For many, the best hope is to keep things working
and _slowly_ advance knowledge in each of those areas.

To admit that advancing knowledge in each area is advantageous is to
question the rational of necessarily doing so slowly.
I'd like to know more about your work environment.
It sounds very different from any that I have worked in or
worked with.

So nobody manages the use of the available resources to take best
advantage of the skills they have?
In the places I have worked or worked with, and the people I've
known, I've never yet seen someone who was simply a "javascript
programmer".

Officially I am a Java and javascript programmer, but I have not written
a single line of Java in the last year, and am unlikely to be able to do
so in the next year.
In almost every case I've witnessed, javascript has been
an 'add-on' technology that web developers are expected to
use, but that employers almost never devote any time or
training towards.

It is fairly obvious form job adverts that many organisations have
little idea of which skills, technical and otherwise, they should expect
to hire in one individual. When someone advertises for a 'web designer
with DHTML' they are asking for a graphic designer and a programmer, two
skills that would rarely be available in equal measure in the same
individual.
Again, I think your current work environment - whatever it
is - does not represent the norm for many, many developers
out there.

That may well be true, I have always programmed for software houses
(mostly working on e-commerce web sites and web applications, as I
presently am). Software houses are, however, very interested in the
efficient and cost-effective creation of reliable and easily maintained
software.

An organisation such as a web design agency may be very differently
managed, but when they find themselves in the business of writing
software maybe they should be looking at how the business of writing
software is practiced professionally.
Certainly not for those developers who aren't even _in_
a work environment.

The degree to which the attitudes and behave of individual amateur
developers may be regarded as professional is not that important.
Good for you. You can be picky.

It is not a question of being "picky", hiring someone to white browser
scripts who cannot write browser script would be an expensive mistake.
Not every company can.

Companies cannot verify that the people they hire possess the skills
they purport to have? I think you will find that they can.
Hell, many web sites are made by _volunteers_! It could be
for their church, their local charity, their boy scout troop,
or whatever. These people may not even be programmers. If
they want some cool javascript functionality on their site,
you would probably tell them "too bad, you can't.

Would I? As I recall I have put considerable effort into demonstrating
that much of what your are calling "cool javascript functionality" can
be achieved without introducing a javascript dependency, and so without
having a negative impact on the viability of any site that uses them.
You don't know enough."

I may in practice make it evened that any given individual doesn't know
enough to handle the issues involved in using javascript on a web site,
but I tend to suggest that the answer to that problem is acquiring the
knowledge.
Whereas I would tell them, "sure, you can do that.
Download X and Y and put Z in your HTML, and it will
work."

And you use a definition of 'work' that falls short. You introduce
dependencies and penalties without properly explaining them, and then
deny their significance when others raise the issues. In short, you give
someone who might be capable of doing better the ability to do harm
without necessarily being aware that they are doing so.
Whose approach do you think _they_ prefer?

When people are doing harm, to their employer, or their employer's
clients, or their own clients, or just some organisation that they have
volunteered to 'help', then they are usually happier to be unaware that
they are doing harm (assuming some personal moral integrity).
That's great, if it solves your specific problem. But is it
general enough to be used by thousands of other people around
the world?

No, of course not. It is general enough to be re-used in any context
within the application that may require a date picker.
If not, then you've solved 1 problem when you could have
solved 1,000 problems with a little more work.

I solved the problem in the context of the problem. Any additional work
solving other people's problems would represent a dishonest use of my
employer's resources.
A few extra k doesn't matter in most cases.
I'm never convinced by theoretical savings, whether it be
reducing code from 10k to 9k, or by speeding up a code block
by 5ms. There comes a point where the "savings" do not justify
the time invested to achieve them.

A large part of the point of the code design/implementation strategy I
have been promoting is that there is no extra time involved in
implementing it. Indeed, because code re-use is maximised the time spent
actually writing code is minimised.
Code bloat only matters if people care.

People care.
If you have 200k of javascript, I agree, people might actually
care. If you have a 30k lib that is cached and used repeatedly
on a site,

And as soon as you have 10 libraries providing separate functionality
you have 10 opportunities for essentially the same code to be appearing
in more than one of them.
I think you would have a hard time finding anyone who
realistically cared.

My CEO maintains that fast web applications sell better, and because he
cares all of the management cares. So, no I don't have to look far to
find someone who cares.
a) Not everyone has the skill to develop low-level reusable
functions such as you have done.

But do the people who don't have the skill also not have the potential
to acquire that skill?
b) People such as yourself who write these functions often
refuse to document and share them.

A layered design based on low-level re-usable components is a design
pattern not a collection of specific code.
c) Therefore, people without the time or skill to write those
functions cannot use your approach.

They can once they have acquired the knowledge to do so.
If I were you - someone repeatedly advocating reusable
low-level functions being combined to achieve a larger
task - then I would certainly be documenting those
functions and making them available to other lesser-skilled
javascript developers, so that everyone could benefit from
my approach. Why don't you?

Because I understand that a code design strategy is independent of
actual code, and that the actual components are amenable to may styles
of implementation with no good reason to believe that any individual
implementation would be automatically superior to one in another style.

What developers need in order to exploit the pattern is an understanding
of the idea and some examples of individual components.

I do have my own low-level reusable components for various
tasks. Many work very well, some could use some more
tweaking. My libraries use these reusable components and
package them into usable form for developers. If they want
to break it down and write things on their own using the
low-level components, that's fine. My approach is to package
them up in usable form so they don't _need_ to do all that
work.

Which is exactly what I have been saying. As soon as you put two such
libraries together any such code they both employ is needlessly
repeated, with the problem increasing as any individual libraries are
added.
I am constantly looking for the best low-level reusable
functions to perform very specific tasks. In fact, I've
asked for assistance several times in this group in writing
some very specific, reusable low-level functions, and people
aren't really interested in the topic.

You are mistaking not being interested in the topic with not being
interested in helping you. You have to remember that everyone knows what
you are going to be doing with any information/examples you are given.
It is not surprising that people should be reluctant to aid you in
making the Internet worse that it could be.
I would think that the regulars here would _love_ to work
together to find the best way to solve specific, low-level
tasks and document them in a repository of reusable code.

You haven't noticed the Usenet archives then?
People such as yourself - who _ADVOCATE_ such a method of
development - do not share your solutions so that others
may benefit.

I put them in a public place, if you don't care to look that is your
choice.

It's a phrase whose meaning should be obvious.

It reads like marketing-speak and so would be assumed to have no real
meaning.
If you've added value to something, you've increased a
positive trait or reduced a negative one. The end result
is worth more, or is superior to the original state. Maybe
you increased productivity, made something more robust, made
something easier to maintain, saved
money, etc, etc.

You used added "value" in the context of someone adopting one of your
"Best Practices" without understanding what the purpose of the "Best
Practice" is, or understanding why they were adopting it. And, as I
pointed out in the paragraph that you edited from your quoted response
(without marking the edit), the change in state that represents this
added "value" would consequently be negligible. As someone working with
a technology of which they are largely ignorant has the capacity to do
enormous damage without being aware that they are doing so describing
this negligible change of state as adding "value" is like characterising
the swatting of a mosquito as adding value to the fight against malaria.
It might sound good but it really doesn't mean much.
Because not everyone is like you, Richard.
Is that a hard concept to understand?

Editing out the paragraph following the question "why?" without any
indication that you have done so is seriously disingenuous. That
paragraph whent on to ask how long it took you to acquire the skills you
have, and how long you would expect to take learning skills you do not
have. You may be right in your implication and there may actually be
people who are capable of acquiring skills instantaneously, but the
majority are like me in that they will have to devote time to learning
anything new.
You don't?

No I don't. If the outcome of a problem solving process is acceptable
then it is a solution to the problem. If that acceptable outcome is not
actually a solution to the stated problem then the initial problem was
incorrectly stated/analysed.
Let's take an easy example - medicine.

Interesting choice. You have been arguing here for a tolerance of
individuals working in a professional capacity without a working
understanding of the technology they are using. How well does that
notion translate into medicine? May the general practitioner be excused
for not finding the time to gain an understanding of skin diseases, or
the surgeon for attempting brain surgery prior to gaining some expertise
in the subject? And is the pharmacist rational in his expectation to be
allowed to work as a surgeon?

The situation is more extreme because the consequences of the
harm that can be done in the field of medicine are potentially lethal,
while in web development they are mostly fiscal.
If I have an incurable disease, I sure would appreciate
having medicine to fight the side-effects, and to delay
the inevitable results of the disease. The problem of the
disease is not solved. But it has been partially solved -
I will be more comfortable, and I will live longer than
if I didn't take the medicine. I sure would appreciate
such a partial solution to the problem. :)

The "problem of the disease" is a poor analyse of the situation. The
problems may be 1. finding a cure for the decease, 2. finding a
prevention for the decease, and 3. finding a palliative for the symptoms
of the decease. Your proposal is a full solution to the problem of
finding a palliative, not a partial solution to either of the other
problems. Indeed it does not even address either of the other problems,
though a solution to either of the other problems would eventually
negate the need for a palliative.
If you believe that your approach is perfect and ideal (or at least
closer than mine) for most people, then I think you are wrong. Sure,
it may be realistic and practical for some, but certainly not most.
IMO.

Go find a high school student who is learning web development
to make a school band web site and wants to use some javascript.

So the criteria for web development "Best Practices" are to be governed
by absolute beginners making amateur web sites?
Ask them if it's realistic and practical to invest weeks of
learning and testing to figure out how browser scripting works,
then spend weeks writing their own low-level reusable functions,
then spend time combining them to perform the specific task
they wanted to achieve on their site. Ask if that approach is
realistic and practical for them,

You have proposed someone who is "learning web development", and so time
spent learning the technologies involved will be valuable, and should be
expected to take time.
when they could have downloaded a solution with 10k of
'code bloat' and had it working in their page in less than an
hour.

You question doesn't make it clear whether it is "learning web
development" or "to make a school bad web site" that is the point of the
exercise. In the latter case you proposal may contribute to the outcome
in a way that does not require any learning of web development. If
learning something is the point of the exercise then learning to deploy
a third party library without understanding it (or the possible
consequences) is barely a contribution at all.
Ask them which approach is more realistic and practical.
<snip>

The judgement of someone who has no understanding of a subject as to
what would be practical and realistic in relation to that subject is of
little value. You would just be asking someone whether they would prefer
not to spend time learning how to go about doing something that they
want to do. It is an appeal to innate idleness in humans, and yes we
would all prefer not to have to spend time learning how to do what we
want to be able to do. However, if pressed, even you high school student
would have to admit that it is not a very realistic desire.

Richard.
 
M

Matt Kruse

Richard said:
It is not necessary to be an expert in order to understand browser
scripting.

It does require extensive learning, trial-and-error, and personal
experience. A reference document is not enough. One needs to experiment with
browsers and quirks in order to build something that is useable, in many
cases.
You are also describing someone who does not need to use javascript at
all, it is not compulsory.

Obviously. _Nothing_ is required. You could write plain text and not learn
HTML, too.
The point is, sometimes some more advanced functionality is desired, and not
everyone can fulfill your 'requirements' to be able to accomplish that
functionality.
Officially I am a Java and javascript programmer, but I have not
written a single line of Java in the last year, and am unlikely to be
able to do so in the next year.

I believe your position makes you _highly_ biased, and I question your
ability to identify with the needs and conditions that a more typical web
developer is faced with. You seem to be unable to grasp that not everyone is
capable of being in the position you are, either in terms of work
environment or ability to learn skills. Your solution for someone who is not
like you seems to be to become more like you. Which is highly unrealistic,
and perhaps not even desireable.

If you were an average web developer without much experience, put into a
position where you needed to develop some javascript functionality, I think
you would be like a deer in headlights. You wouldn't know what to do. Your
only recommendation would be to spend weeks or months learning the skills
required to implement things from scratch, which is a naive and completely
impractical suggestion for most.
The degree to which the attitudes and behave of individual amateur
developers may be regarded as professional is not that important.

You missed the point entirely.
Many people learn and practice web development and javascript outside of a
work environment. The idea of spending many hours learning a programming
language is not at all practical.
And as soon as you have 10 libraries providing separate functionality
you have 10 opportunities for essentially the same code to be
appearing in more than one of them.

Is that a problem? Even code you've posted yourself has code duplication,
such as multiple instances of a returnFalse() function, etc.
Having the same code appear multiple times is not ideal, but it's only bad
if it has a negative effect on performance or some other factor.
But do the people who don't have the skill also not have the potential
to acquire that skill?

Sometimes they don't, no.
Often employers don't have the free time to devote to properly training
people or giving them the opportunity to learn.
In cases where peoeple are volunteering their time or learning outside of
work, they may have families and other things which prevent them from
devoting the required time to learn.
And finally, some people just aren't programmers at all, and have no
interest in learning the particulars of something that they can download and
use without a big learning curve.
A layered design based on low-level re-usable components is a design
pattern not a collection of specific code.

I realize this.
But if you have solved the problem of, for example, finding the position or
size of an object in a way that works in as many browsers as possible and as
many specific cases as possible, that code can be reused by others rather
than them writing it from scratch and discovering all the quirks which need
to be adjusted for between browsers.
They can once they have acquired the knowledge to do so.

This prerequisite of yours has already been shown to be unrealistic and
impractical for many people.
You are mistaking not being interested in the topic with not being
interested in helping you. You have to remember that everyone knows
what you are going to be doing with any information/examples you are
given. It is not surprising that people should be reluctant to aid
you in making the Internet worse that it could be.

And you know the term used for such people? Elitist assholes. They're the
people no one likes in person and no one invites to parties. I'm sure you
understand ;)

The fact is, as I am redesigning my javascript site, I am putting in a
section for low-level solutions to specific problems. If you want to do X,
then here is a function Y which solves that very specific problem.

My libraries will of course make use of the low-level functionality, but the
goal is to have those available separately also, so that if someone wants to
find just a specific piece of functionality which they can include in their
work, it is there. Since some functionality can be difficult to develop for
in a browser-neutral way, such low-level functions are best developed with
the advice and suggestions of several people, IMO. A single author can
rarely accomplish the same level of detail and thorougness that several can.
You haven't noticed the Usenet archives then?

You think that usenet archives are a better repository than a single web
site with contents that reflect the concensus of a number of expert
developers?
It reads like marketing-speak and so would be assumed to have no real
meaning.

Like most of the novels you write in this group ;)
So the criteria for web development "Best Practices" are to be
governed by absolute beginners making amateur web sites?

Perhaps.
Expert developers rarely need to consult 'best practices' documents.
 
M

Matt Kruse

Randy said:
You are an awesome Theorist Richard. But Theory, the Web and Reality
are a disaster in the making when you try to force Theory onto the
Web and Reality. The difference is night and day.

Yeah. What he said, much better than I ever do ;)

Theory is great. But it doesn't necessarily do any good in many real-world,
every-day problems.

I think theory is interesting (and great for more advanced developers), but
I much prefer to deal in reality. It doesn't matter if you think people
OUGHT to spend hours learning javascript and write code from scratch using
their own reusable low-level functions.

IT AINT GONNA HAPPEN!

You can either shield your eyes from this reality and continue with the same
old mantra which doesn't actually help anyone, or you can accept the reality
and develop solutions, guides, suggestions, and libraries which help people
in real-world situations.

I'm not saying I take the absolute best approach possible. My code needs
improvements (many of which I've already developed, but documenting things,
creating a web site with examples, and supporting them is extremely
time-consuming), but I do believe that I'm doing more of a service to the
web community than Mr. Cornford, Mr. Stockton, et al, who continue to
complain about my approach, and also refuse to make any real constructive
criticisms of my code. They can talk theory all they want, but in reality
I'm not sure they really help many people. *shrug*
 
V

VK

Michael said:
This might also be a good time to follow on and dispel the idea about
hash 'arrays'.

It's going to be more difficult than this spring because besides
Microsoft
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjdictionary.asp>


I now got the Mozilla Foundation support:
<http://www.mozilla.org/projects/xpcom/hashtable-guide.html>

Good luck though, my pen is still ready ;-)

frames and form elements addressing
Academically very right, but supposed to deal with some abstract ideal
browser implementation. As there is no such, should we mention
particular issues of earthy rivals (IE & FF at least).
<http://www.geocities.com/schools_ring/ArrayAndHash.html#HTMLCollection>
has some inspirational cases linked.

eval() is evil

But runtime code generation can be very effective (or even the only
option). Should we mention new Function(args, body) method as a legal
alternative to eval() ?
 
L

Lasse Reichstein Nielsen

VK said:
It's going to be more difficult than this spring because besides
Microsoft
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjdictionary.asp>

.... which show an example of a dictionary, which is a mapping from keys
to values, and not a Javascript array ...


.... which show an implementation of a hashtable, and states that it is
different from an array (and how it is different).
But runtime code generation can be very effective (or even the only
option). Should we mention new Function(args, body) method as a legal
alternative to eval() ?

No, that's evil too :)

Runtime code generation is rarely, if ever, needed. In the few, highly
specialized, cases where it is, it will hopefully be an experienced
developer who is doing it. Working with code as stings is extremely
unsafe and should be avoided if at all possible.

I have still to see a case of runtime code generation where it's not a
testing utility that executes user entered Javascript (which isn't really
generating) or a re-implementation of a newer feature for older browsers
(like apply). Modern browsers don't need code generation.
/L
 
V

VK

Detecting Browser Versions
.... and related scripts.

I think that really best practice for object/method detection should be
the usage of "in" operator. It's nice that JavaScript converts
undefined and null into boolean false for us, but it seems a bit durty
and may hurt you when moving on strictly typed languages.

So instead of
if ( (someObject) && (someObject.someMethod) )

we should use:
if ( (someObject in objectContainer) && (someMethod in someObject) )

As objectContainer nearly always is window, the most common case would
be:
if ( (someObject in self) && (someMethod in someObject) )
// using "self" reference to the *current* window is more reliable
// than simply "window" because "window" may be contectually
// ambiguous in some very rare but possible cases.
 
R

Randy Webb

VK said the following on 10/26/2005 2:42 PM:
.... and related scripts.

I think that really best practice for object/method detection should be
the usage of "in" operator. It's nice that JavaScript converts
undefined and null into boolean false for us, but it seems a bit durty
and may hurt you when moving on strictly typed languages.

So instead of
if ( (someObject) && (someObject.someMethod) )

we should use:
if ( (someObject in objectContainer) && (someMethod in someObject) )

Test case where it is better? It would seem to be slower but may not be.
As objectContainer nearly always is window, the most common case would
be:
if ( (someObject in self) && (someMethod in someObject) )
// using "self" reference to the *current* window is more reliable
// than simply "window" because "window" may be contectually
// ambiguous in some very rare but possible cases.

How is using self to point to the window object less error prone than
using window? Without giving it a lot of though, window.property would
seem to be less error-prone than self.property for no other reason than
scope issues.
 
M

Michael Winter

On 26/10/2005 19:42, VK wrote:

[snip]
I think that really best practice for object/method detection should
be the usage of "in" operator.

Why? That will throw a syntax exception in several browsers.
It's nice that JavaScript converts undefined and null into boolean
false for us,

Yes, it is. If you don't like that, then use the typeof operator. Just
be aware that IE considers host object methods as objects, not functions.
but it seems a bit durty and may hurt you when moving on strictly
typed languages.

What on Earth does that have to do with /anything/?

[snip]

Mike
 
T

Thomas 'PointedEars' Lahn

VK said:
... and related scripts.

I think that really best practice for object/method detection should be
the usage of "in" operator.

Why should a not far enough downwards compatible feature be considered
"best practice"? typeof ... != "undefined" is sufficient in most cases
and downwards compatible to JavaScript 1.1, JScript 1, ECMAScript 1.

If really an ECMAScript 3 compliant approach would be taken, it would not be
the "in" operator but the hasProperty() method which can much more easily
be tested for than the former. Besides, "in" would seldom suffice as
before calling a method you would need to make sure that it *is* a method
and not a non-function property.

Your assumption that `window' "nearly always" refers to the Global Object
is wrong, by the way. There is a low probability that it does not within
a HTML document context, but JS can be used in other contexts. And `self'
is merely a property of `window', if existent, not of the Global Object;
using it (untested) is only making bad things worse.


PointedEars
 
V

VK

Thomas said:
Why should a not far enough downwards compatible feature be considered
"best practice"?

By "not far enough" you mean NN 2.x - NN 4.x ? IE supports it since
3.02
If some other browser still doesn't have it implemented properly, the
primary task would be to see such browser disappeared from the human
memory as quick as possible, rather than support it an any way.

The most important is that if (someObject) method fails easily in too
many curcumstances appeared after prototypes and constructors
introduction. Check this sample:

<html>
<head>
<title>Testcase</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function test() {

self.abort = undefined;

// Bad practice
// if (someObject.someMethod){...) method
// fails on prototype change
if (abort) {
alert('I still know it was originally here');
}
else {
alert('Oops, I\'ve been easily cheated');
}

// Good practice:
// if (someObject in objectContainer) {...} method
// works reliably on prototype change
// As one cannot use delete() on default property,
// you cannot be mislead in any situation
if('abort' in self) {
alert('Do not try to cheat me!');
}
else {
alert('Oops, I\'ve been cheated too');
}
}

alert(self.hasProperty)
</script>
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="">
<input type="button" name="Button01" value="Test" onclick="test()">
</form>
</body>
If really an ECMAScript 3 compliant approach would be taken, it would not be
the "in" operator but the hasProperty() method which can much more easily
be tested for than the former.

Where did you get method? You mean HasProperty moniker from .Net
framework? It has no relation with the discussion.
Besides, "in" would seldom suffice as
before calling a method you would need to make sure that it *is* a method
and not a non-function property.

Why in the name you need to check the type of property in question?
What can it prove? Even if it's indeed a method (so it's typeof
"function"), what proof do you have that this is *that* method and not
some bogus? And even if it's indeed *that* method, what proof do you
have that it was implemented as documented? You can only protect
yourselve from initial "Object expected error" by doing
if ( (neededObject in self) && (neededStuff in neededObject) ) {...}
The rest remains in the hands of the Lord and browser makers.

Your assumption that `window' "nearly always" refers to the Global Object
is wrong, by the way. There is a low probability that it does not within
a HTML document context, but JS can be used in other contexts. And `self'
is merely a property of `window', if existent, not of the Global Object;
using it (untested) is only making bad things worse.

"self" has the only context to be. Unless you've created a "self"
variable and did your whole script dizzy:
....
self = something;
// var self = something ?
// window.self = something ?
....

As "self" is one of so-called "tasty words" for identifiers, I see this
happens here and there and should be each time pointed.
 
V

VK

Thomas said:
Why should a not far enough downwards compatible feature be considered
"best practice"?

By "not far enough" you mean NN 2.x - NN 4.x ? IE supports it since
3.02
If some other browser still doesn't have it implemented properly, the
primary task would be to see such browser disappeared from the human
memory as quick as possible, rather than support it an any way.

The most important is that if (someObject) method fails easily in too
many curcumstances appeared after prototypes and constructors
introduction. Check this sample:

<html>
<head>
<title>Testcase</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function test() {

self.abort = undefined;

// Bad practice
// if (someObject.someMethod){...) method
// fails on prototype change
if (abort) {
alert('I still know it was originally here');
}
else {
alert('Oops, I\'ve been easily cheated');
}

// Good practice:
// if (someObject in objectContainer) {...} method
// works reliably on prototype change
// As one cannot use delete() on default property,
// you cannot be mislead in any situation
if('abort' in self) {
alert('Do not try to cheat me!');
}
else {
alert('Oops, I\'ve been cheated too');
}
}

alert(self.hasProperty)
</script>
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="">
<input type="button" name="Button01" value="Test" onclick="test()">
</form>
</body>
If really an ECMAScript 3 compliant approach would be taken, it would not be
the "in" operator but the hasProperty() method which can much more easily
be tested for than the former.

Where did you get method? You mean HasProperty moniker from .Net
framework? It has no relation with the discussion.
Besides, "in" would seldom suffice as
before calling a method you would need to make sure that it *is* a method
and not a non-function property.

Why in the name you need to check the type of property in question?
What can it prove? Even if it's indeed a method (so it's typeof
"function"), what proof do you have that this is *that* method and not
some bogus? And even if it's indeed *that* method, what proof do you
have that it was implemented as documented? You can only protect
yourselve from initial "Object expected error" by doing
if ( (neededObject in self) && (neededStuff in neededObject) ) {...}
The rest remains in the hands of the Lord and browser makers.

Your assumption that `window' "nearly always" refers to the Global Object
is wrong, by the way. There is a low probability that it does not within
a HTML document context, but JS can be used in other contexts. And `self'
is merely a property of `window', if existent, not of the Global Object;
using it (untested) is only making bad things worse.

"self" has the only context to be. Unless you've created a "self"
variable and did your whole script dizzy:
....
self = something;
// var self = something ?
// window.self = something ?
....

As "self" is one of so-called "tasty words" for identifiers, I see this
happens here and there and should be each time pointed.
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top