Why should I eschew prototype.js?

N

nolo contendere


In this very thread in fact.
Lots, but I don't have time to go through all of them right now.
However, one good illustration is the least you deserve.

I appreciate it.
Take this code form the latest (1.6.0) version of Prototype.js:-

| var Hash = Class.create(Enumerable, (function() {
| if (function() {
| var i = 0, Test = function(value) { this.key = value };
| Test.prototype.key = 'foo';
| for (var property in new Test('bar')) i++;
| return i > 1;
| }()) {
| function each(iterator) {
| var cache = [];
| for (var key in this._object) {
| var value = this._object[key];
| if (cache.include(key)) continue;
| cache.push(key);
| var pair = [key, value];
| pair.key = key;
| pair.value = value;
| iterator(pair);
| }
| }
| } else {
| function each(iterator) {
| for (var key in this._object) {
| var value = this._object[key], pair = [key, value];
| pair.key = key;
| pair.value = value;
| iterator(pair);
| }
| }
| }
| ...

- What this appears to represent is the conditional creation of a
function based upon (rather complex) test. But in ECMAScript terms this
is actually one big syntax error, because inside each of the
BlockStatement branches of the - if-else - there are what appear to be
function declarations, and BlockStatemen may only contain Statements
(not FunctionDeclarations (FunctionDeclarations and Statements being the
two distinct syntactic units from which ECMAScript Programs and function
bodies are constructed)).

Obviously if the 3 or 4 browsers with which Prototype.js 'works'
actually generated a syntax error that fact would have been noticed, so
what is happening? The first part of the answer is that JavaScript(tm)
has a non-standard syntax extension that is a FunctionStatement, which
(being a Statement) may appear inside a BlockStatement and can be
conditionally evaluated. ECMAScript allows for such extensions, though
they usually must be avoided when creating cross-browser code. The
second part of the answer is that JScript (and many other ECMAScript
implementations, including Opera's) are tolerant enough to
unconditionally treat these out of context 'FunctionDeclarations' as
FunctionDeclarations. But because FunctionDeclarations are processed
during variable instantiation, before any actual code execution, in
these environments the effect of the above is the equivalent of:-

var Hash = Class.create(Enumerable, (function() {
function each(iterator) {
for (var key in this._object) {
var value = this._object[key], pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
}
}
function each(iterator) {
var cache = [];
for (var key in this._object) {
var value = this._object[key];
if (cache.include(key)) continue;
cache.push(key);
var pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
}
}
if (function() {
var i = 0, Test = function(value) { this.key = value };
Test.prototype.key = 'foo';
for (var property in new Test('bar')) i++;
return i > 1;
}()) {

} else {

}
...

- Where the first - each - FunctionDeclaration results in the creation
of a function object and the assignment of a reference to that function
to the 'each' property of the variable object, and then the second -
each - FunctionDeclaration - results in the creation of a second
function object which is then assigned to the 'each' property of the
variable object, replacing the first. So in these environments it is the
second FunctionDeclaration that defines 'each', unconditionally, and
the - if-else - statement is effectively empty, making its execution
worthless.

Now if this code 'works' at all it 'works' mostly by coincidence as it
is relying on a non-standard extension wherever the - if-else - is
effective, and where the FunctionDeclaration are unconditionally acted
upon the result must only 'work' due to the order in which the two
declarations appear.

Of course the conditional creation of function objects is trivial in
javascript in a way that fully conforms with the ECMAScript
specification, and so in a way that can be expected to be fully
cross-browser and consistently executed in ECMA 262 3rd Ed. implementing
environments. Such code would be something like:-

var Hash = Class.create(Enumerable, (function() {
var each;
if (function() {
var i = 0, Test = function(value) { this.key = value };
Test.prototype.key = 'foo';
for (var property in new Test('bar')) i++;
return i > 1;
}()) {
each = function (iterator) {
var cache = [];
for (var key in this._object) {
var value = this._object[key];
if (cache.include(key)) continue;
cache.push(key);
var pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
}
}
} else {
each = function (iterator) {
for (var key in this._object) {
var value = this._object[key], pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
}
}
}
...

- replacing the 'syntax error' FunctionDeclaration with Expression
Statements where a Function Expression is assigned to an Identifier. The
result is fully ECMAScript standard and so will 'work' consistently in
all past, present and future ECMA 262 3rd Ed. conforming
implementations.

Why has a library not been written this way? Obviously it's not your
responsibility to do it, or to even know the reason why it hasn't been
done thus far, but if so many people are in error, and it causes you
any distress, it would behoove you to write one, or at least begin
one. Perhaps set up a project? Clearly you care a lot about this
subject, and have invested much time in it. This is just another
avenue by which you can participate in -- and even shape -- the future
of how javascript is used.
It is simply the case that anyone knowing javascript would have written
the original code in this final form. So would not be writing code that
functioned purely by coincidence but instead they would be programming.

The problem with the way this sort of ignorance of javascript results in
code that only works by coincidence is highlighted by browsers like
Opera. Opera currently acts like JScript, and unconditionally acts on
the FunctionDeclarations out of their (otherwise syntax error) context
but while Opera has an ECMA 262 conforming javascript implementation,
they also aim to emulate JavaScript(tm), and so may introduce
JavaScript(tm)'s FunctionStatement extension at any moment. And so code
that works by coincidence because of the order of the
'FunctionDeclarations' may find itself suddenly conditionally evaluating
FunctionStatements with any next version of Opera, and what these
branches do in that versions of Opera may be totally inappropriate.

So this is the browser's problem. They are too permissive. But if you
think about it, if 90% of people do something one way, and that way
doesn't conform to "the standard" (in this case, ECMA), doesn't the
way most people do it BECOME the standard? It may be horrific in its
implementation, syntax, whatever, but so is HTTP. So you either adapt
and use it, or try to make change.
The Prototype.js approach results in code that cannot be expected to
work in any more browsers than those in which it has been demonstrated
to 'work', and so cannot even be expected to 'work' with the future
versions of that those browsers. This cannot be a viable approach to
creating cross-browser code, and it does not.

Again, this may be the browser's fault then. Bear in mind that browser
developers do have to cater to existing web pages, and have all sorts
of testing to try to ensure that nothing breaks in future versions. I
highly doubt that just because a page doesn't conform to ECMA
standards, the browser developers will say "screw that web page, if
they don't follow ECMA they don't get a proper rendering in our
browser." This may work if the percentage of "bad" web pages were
vanishingly small, but hey, this is the real world where people are
stupid and market share is of vital importance to a browser's
continued existence. I'm not saying I'm encouraging bad coding, or
stupidity, but I'm being a realist. Once all market share is captured,
THEN you can begin to gradually enforce whichever standards are the
best. But until then, it's a free-for-all.
That is quite a bit of writing in order to demonstrate that the authors
of Prototype.js don't know javascript. Similar demonstrations are
possible for bad design, ridiculous inefficiencies, avoidable bad
practices and much else besides, but I don't have time right now so you
will have to look them up in the archive.

I truly do appreciate your perspective. I did a little research on
you, and you appear to be a very intelligent individual, although (and
I don't mean to be destructively critical) a bit of an idealist/
purist--which the world does need, but isn't the way the world works.
The code itself is about a quarter as efficient as it could be, but
certain aspects of the design promote its extremely inefficient use, so
examples you will see are often orders of magnitude worse than that.
Fast computers mitigate that problem, but you would find systems created
with Prototype.js become unacceptably sluggish at much lower levels of
complexity.


Maybe, but that doesn't stop my boss continually wanting the client-side
code our web applications to run faster. He maintains that they are
easier to sell when they are fast, and then that they are easier to sell
if they have ever more bells and whistles. Obviously those are
contradictory demands.


At least for as long as you avoid understanding how those effects work,
and so how trivial they are to create for yourself.

Again, if they are so trivial, why wouldn't a "good" library have been
written? Wouldn't evolution cause the "good" librarues to bubble up
and become the de facto standard? Wouldn't "bad libraries" break in
future revs, independent browsers, etc, and the "good libraries" gain
mind- and market-share with each manifestation of the "bad
libararies'" failure?
 
G

Gregor Kofler

nolo contendere meinte:
Again, this may be the browser's fault then. Bear in mind that browser
developers do have to cater to existing web pages, and have all sorts
of testing to try to ensure that nothing breaks in future versions.

You know what? There are websites (not conforming to standards, sure),
wich looked perfectly ok on IE6, but break more or less seriously on IE7.
I highly doubt that just because a page doesn't conform to ECMA
standards, the browser developers will say "screw that web page, if
they don't follow ECMA they don't get a proper rendering in our
browser." This may work if the percentage of "bad" web pages were
vanishingly small, but hey, this is the real world where people are
stupid and market share is of vital importance to a browser's
continued existence. I'm not saying I'm encouraging bad coding, or
stupidity, but I'm being a realist. Once all market share is captured,
THEN you can begin to gradually enforce whichever standards are the
best. But until then, it's a free-for-all.

Websites all break in different ways. It's impossible to care about all
of them.
I truly do appreciate your perspective. I did a little research on
you, and you appear to be a very intelligent individual, although (and
I don't mean to be destructively critical) a bit of an idealist/
purist--which the world does need, but isn't the way the world works.

What's your point? You're looking for points against prototype, but
whenever points follow you dismiss them with empty statements.

Again, if they are so trivial, why wouldn't a "good" library have been
written?

Perhaps mine *could* be better. But I don't want to put in all the
effort needed for proper testing and documentation. And I deem those
things important, when publicising a library (contrary to the prototype
authors). Other authors might have similar or other reasons.
Wouldn't evolution cause the "good" librarues to bubble up
and become the de facto standard? Wouldn't "bad libraries" break in
future revs, independent browsers, etc, and the "good libraries" gain
mind- and market-share with each manifestation of the "bad
libararies'" failure?

I suppose that's the reason, why the least standards compliant browser
has the marginal market share of, say, 80 percent?


Gregor
 
N

nolo contendere

nolo contendere meinte:


You know what? There are websites (not conforming to standards, sure),
wich looked perfectly ok on IE6, but break more or less seriously on IE7.

Of course, I'm saying that the future versions of browsers would make
the attempt to break as few sites out there as possible. If the
majority of sites DON'T conform to ECMA standards, the deveoplers will
cater towards THAT first, and not the standards.
Websites all break in different ways. It's impossible to care about all
of them.


What's your point? You're looking for points against prototype, but
whenever points follow you dismiss them with empty statements.

No, I don't dismiss them. I appreciate the points. My argument is that
however wonderful the vision is of a completely standards compliant
web, reality differs. It's pointless to rail against something one
deems "bad", and not do anything about it. Either adapt, or strive to
improve it. Here, Robert does strive to improve it a little by
engaging in this discussion, but his efforts would be more fruitful
simply to come up with a better library.
Perhaps mine *could* be better. But I don't want to put in all the
effort needed for proper testing and documentation. And I deem those
things important, when publicising a library (contrary to the prototype
authors). Other authors might have similar or other reasons.

So by saying that you need all that effort, you are contradicting the
statement that it is trivially easy. You can't have it both ways.
I suppose that's the reason, why the least standards compliant browser
has the marginal market share of, say, 80 percent?

You're missing the point. I'm saying if you have enough market share,
rightly or wrongly, you MAKE the standards.
 
T

Thomas 'PointedEars' Lahn

nolo said:
Of course, I'm saying that the future versions of browsers would make
the attempt to break as few sites out there as possible. If the
majority of sites DON'T conform to ECMA standards, the deveoplers will
cater towards THAT first, and not the standards.

And therefore writing non-standard code that breaks *now* is a good thing?
That's just ridiculous.
You're missing the point. I'm saying if you have enough market share,
rightly or wrongly, you MAKE the standards.

That is what companies like Microsoft want naive people like you to believe.


PointedEars
 
N

nolo contendere

And therefore writing non-standard code that breaks *now* is a good thing?
That's just ridiculous.

Why do you infer that the non-standard code breaks now? Richard's
stance was that it DOES work, albeit coincidentally.
That is what companies like Microsoft want naive people like you to believe.

I don't think I'm being naive. I think hoping/expecting/suggesting
that no one use "imperfect" libraries is naive. If you disagree with
the status quo, and you know better and have the ability, make change.
 
G

Gregor Kofler

nolo contendere meinte:
Why do you infer that the non-standard code breaks now? Richard's
stance was that it DOES work, albeit coincidentally.

This very example. Richard picked an example to illustrate the bad code
quality, nothing else.
I don't think I'm being naive. I think hoping/expecting/suggesting
that no one use "imperfect" libraries is naive.

I'd say no one on clj hopes/expects/suggests that *no one* uses
imperfect libraries. However, if one is willing and able, there might be
better ways.

Anyway, since you are perfectly satisfied with prototype and can live
with it's shortcomings: use it, and end this futile discussion.

EOD, Gregor
 
N

nolo contendere

Thomas 'PointedEars' Lahn said the following on 11/13/2007 12:31 PM:



What is more ridiculous is to believe that everybody is going to write
"perfect" code. Now or ever.



Oh monkeys ass.

LMMAO!
 
D

Doug Miller

Thomas 'PointedEars' Lahn said the following on 11/13/2007 12:31 PM:

What is more ridiculous is to believe that everybody is going to write ^^^^^^^^^
"perfect" code. Now or ever.

You misspelled "anybody". <g>
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 11/13/2007 12:31 PM:

What is more ridiculous is to believe that everybody is going to write
"perfect" code. Now or ever.

I did not state anything about "perfect code", you just made that up. That
aside, technical newsgroups like this exist to increase understanding. If
no poster would believe that it is possible to convince a reasonable number
of readers that it is better to write good code, this newsgroup would have
lost its purpose and all people who post now could stop posting.

That it still exists, and that people knowing more still provide people
knowing less with corrections, suggestions and better code proves that you
are utterly wrong.


PointedEars
 
M

Matt Kruse

That
aside, technical newsgroups like this exist to increase understanding.

And also to inflate the egos of people have a good technical
understanding and want to flaunt it for all to see by criticizing
everyone they can. It's amusing to watch sometimes.

This group exists for more than to simply reduce all problems to the
most efficient and standards-compliant code that could possibly be
written. There are Javascript-related questions that are only
partially technical. For example, recent discussions on libraries
point out that people have different priorities. If someone comes here
looking for advice on the pros and cons of library X, the technical
issues with the library is only part of the equation. Even if a
library has technical problems, using it still may be the best
business decision, and that overall discussion is still Javascript-
related.

Technical perfection is not _THE_ goal, but _A_ goal.

Critiques of code and offering advice on why it is good or bad and how
it could be improved is a great thing that should always be welcome.
But not at the expense of discussing what the OP is really trying to
figure out. That's where so many regulars on this group get it wrong.
IMO.

I would still like to see answers from some of the hardcore critics
here about real-world situations and what they would recommend when
real-world problems and priorities need to be taken into
consideration. When technical merit is probably not the #1 concern,
but maybe down the list a bit. Then falling back to the same old
"libraries suck" arguments and pointing to all coding practices that
conflict with the "standards" do you no good, and many here don't seem
to be able to carry on an intelligent conversation once their mantra
is irrelevant.

Matt Kruse
 
D

dhtmlkitchen

nolo contendere said the following on 11/13/2007 12:14 PM:



I have been saying that in this group for years. Give up, it doesn't do
any good.

90% of the people that write Javascript don't know what ECMAScript is.
Of the remaining 10%, 90% of those don't care what ECMAScript is.
The other 1% post here proclaiming it as the savior of Javascript.

ECMAScript, in its current incarnation, was nothing more than an effort
to "standardize" what was already in place. And probably for no other
reason than to be able to say "There is a standard". And, it was a
stroke of marketing/research genius on the part of Microsoft.





It was Richard, not Robert, but, I don't think Richard was trying to
improve on Prototype.js as much as show the flaws in it. There is
another one that is, perhaps without a doubt, the mostly hotly debated
in this group and that is the use of $ as a function name. The main
issue is "ECMAScript says it is intended for machine generated code" and
people grasp onto that and want to condemn the practice simply because
"ECMAScript says so".
that's one issue. The other is that it's not semantic.

A method should do what it says. What does $ say it does? If it were a
shortcut to document.getElementById, I'd call unnecessary delegation,
but that's not the case.

The $ has been so overloaded to do xpath, et c in jQuery. In a way,
it's like those html pages where every tag is div.
The $ function itself is another area where it could be improved simply
by removing some of it. It is over-written for what it is used for.
I'm in complete agreement. All the getBySelector functionality. YAGNI.
The only one time I needed something like that was when I wrote the
CssEditor, and then I really needed to parse the styleSheet and
capture clicks on elements matching the most specific selector.

Another place it was used is Selenium, although I do not use those
selectors in Selenium becauise selenium already has xpath which is
very good at what it does.
I don't think they "make" the standard as much as they "become" the
standard. Microsoft drives this market, whether people admit it or not.
It isn't a pro-MS or anti-MS sentiment, it is just a fact. If MS came
out next week and proclaimed "The only markup language we will support
in the future is MSML(Microsoft Markup Language), the only script
language we will support is MSScript (Microsoft Script), and nothing
else". Then the rest of the browser world would flip on it's head in an
effort to support them and the W3C would become a thing of the past.
I doubt that. So many HTML pages now, and people need to log in to
their pages, et c. If IE doesn't support that feature (HTML) then it
would fall out of favor. MS would have to get users on to a new
platform first, and get enogh pgs developed on that platrofm to make
it really attractiuve,.
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 11/13/2007 2:20 PM:

Let me check and re-read what I wrote. Nope, I never said you stated
anything about perfect code. Nope, sure didn't. Do you see where I did?

As you appear to have impaired vision, I have marked it for you above.
Didn't think so. Now, who is "making things up"?

You are.
No, that is not why they exist. If understanding is increased then it is
a by-product, not the product of the group.

A matter of opinion.
Your problem is you think that any code that doesn't follow some
"standard" to the letter isn't "good code". You couldn't be further from
the truth when it comes to writing cross-browser scripts for the web.

You are an idiot. Any code has to be written according to some convention
or it could not qualify as good code; that is, code that does not only run
in a single test environment. Adhering to the convention of a standard,
especially *the* international standard for the programming language, is
vital for it to become interoperable. Without that property, it definitely
qualifies as bad code.


PointedEars
 
G

Gregor Kofler

Randy Webb meinte:
I don't think they "make" the standard as much as they "become" the
standard. Microsoft drives this market, whether people admit it or not.
It isn't a pro-MS or anti-MS sentiment, it is just a fact. If MS came
out next week and proclaimed "The only markup language we will support
in the future is MSML(Microsoft Markup Language), the only script
language we will support is MSScript (Microsoft Script), and nothing
else". Then the rest of the browser world would flip on it's head in an
effort to support them and the W3C would become a thing of the past.

Come on... MS isn't even able to make their IE7 the "standard" browser.
People stick rather to the wretched interface of IE6, than "learn" to
use the added comfort of alternative products.

Gregor
 
T

Thomas 'PointedEars' Lahn

Randy said:
[...] You can't get a new Windows based PC manufacturer to pre-install a
different browser because MS won't allow it.

Yes, you can. M$ has lost that case already, and it is unlikely they will
try again.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 11/15/2007 5:17 AM:
Randy said:
[...] You can't get a new Windows based PC manufacturer to pre-install a
different browser because MS won't allow it.
Yes, you can. M$ has lost that case already, and it is unlikely they will
try again.

Whatever you say, kiddie. It doesn't help your credibility any when you
fall prey to the "cool" stuff like referring to Microsoft as M$, it
detracts from it.

| Learn to read what you are replying to.
| Learn to understand what other people have written.
| Learn the basic vocabulary of a culture you are participating in.
-- Harald Blahovec (translated)

That said, we are pretty much off-topic already with *your* introducing
Microsoft into the equation. Speaking of which, they do have paid a lot
of $s as results of the lawsuits and appeals of competitors against the
aforementioned practice :)


PointedEars
 
V

VK

I had not realized prototype.js was such a hot topic

For two years at least or even more. More exactly: the usage of
"solution size" libraries in JavaScript as such, prototype.js is just
a banner of this fight IMHO :)

I personally do not stand with the kind of argument "as the result
people will not learn JavaScript". One may think that the the whole
army of C++ programmers spending their days in for(x=y;x<z;++x) and
similar programming. Just give me a break! 95% of programming in an
average company consists of linking and registering different
libraries, calling their methods over pre-filled drop-downs and
searching through the help what a hey method does what I need in
A=>B=>C=>D=>E=>F=>G=>H object - the last often is the main time
consumer :) I now some libraries that came into life exactly because
it was quicker to write something of your own rather than memorize
some too weird named or placed properties and methods of a 3rd party
library.

IMHO there are two differences and problems for JavaScript libraries.
1) All DLL are written with Windows and Visual Studio in mind.
Respectively if one registered a new DLL and some weird stuff started,
normally one files complain/bug report to DLL producer. JavaScript
libraries are some creations "out of time and space". So it is often
some one linked Dojo, jQuery, Prototype and a couple more, the browser
gets crazy of it, and where to look for help? Who has to get your bug
report (or misuse explanation)? Often clj is chosen for that for the
lack of any other evident place - and I definitely understand that
people here are refusing to accept the role of a world-wide free 3rd
party libraries maintenance and correction.

2) The formation of JavaScript libraries was and remains up till now a
totally anarchical process. There is not any RFC or any other commonly
accepted technical documents about JavaScript structuring,
interfacing, naming or documenting. As a result the progress in the
area reminds me a bunch of ants dragging something big to the ant
house: it seems like everyone is working together but really each one
is pushing to his own side, so the slow movement happens only because
the resulting vector is a bit above zero and going to the right
direction. :)
 
D

dhtmlkitchen


In this very thread in fact.
Lots, but I don't have time to go through all of them right now.
However, one good illustration is the least you deserve.

I appreciate it.


Take this code form the latest (1.6.0) version of Prototype.js:-
| var Hash = Class.create(Enumerable, (function() {
| if (function() {
| var i = 0, Test = function(value) { this.key = value };
| Test.prototype.key = 'foo';
| for (var property in new Test('bar')) i++;
| return i > 1;
| }()) {
| function each(iterator) {
| var cache = [];
| for (var key in this._object) {
| var value = this._object[key];
| if (cache.include(key)) continue;
| cache.push(key);
| var pair = [key, value];
| pair.key = key;
| pair.value = value;
| iterator(pair);
| }
| }
| } else {
| function each(iterator) {
| for (var key in this._object) {
| var value = this._object[key], pair = [key, value];
| pair.key = key;
| pair.value = value;
| iterator(pair);
| }
| }
| }
| ...
- What this appears to represent is the conditional creation of a
function based upon (rather complex) test. But in ECMAScript terms this
is actually one big syntax error, because inside each of the
BlockStatement branches of the - if-else - there are what appear to be
function declarations, and BlockStatemen may only contain Statements
(not FunctionDeclarations (FunctionDeclarations and Statements being the
two distinct syntactic units from which ECMAScript Programs and function
bodies are constructed)).
Obviously if the 3 or 4 browsers with which Prototype.js 'works'
actually generated a syntax error that fact would have been noticed, so
what is happening? The first part of the answer is that JavaScript(tm)
has a non-standard syntax extension that is a FunctionStatement, which
(being a Statement) may appear inside a BlockStatement and can be
conditionally evaluated. ECMAScript allows for such extensions, though
they usually must be avoided when creating cross-browser code. The
second part of the answer is that JScript (and many other ECMAScript
implementations, including Opera's) are tolerant enough to
unconditionally treat these out of context 'FunctionDeclarations' as
FunctionDeclarations. But because FunctionDeclarations are processed
during variable instantiation, before any actual code execution, in
these environments the effect of the above is the equivalent of:-
var Hash = Class.create(Enumerable, (function() {
function each(iterator) {
for (var key in this._object) {
var value = this._object[key], pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
}
}
function each(iterator) {
var cache = [];
for (var key in this._object) {
var value = this._object[key];
if (cache.include(key)) continue;
cache.push(key);
var pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
}
}
if (function() {
var i = 0, Test = function(value) { this.key = value };
Test.prototype.key = 'foo';
for (var property in new Test('bar')) i++;
return i > 1;
}()) {
} else {

- Where the first - each - FunctionDeclaration results in the creation
of a function object and the assignment of a reference to that function
to the 'each' property of the variable object, and then the second -
each - FunctionDeclaration - results in the creation of a second
function object which is then assigned to the 'each' property of the
variable object, replacing the first. So in these environments it is the
second FunctionDeclaration that defines 'each', unconditionally, and
the - if-else - statement is effectively empty, making its execution
worthless.
Now if this code 'works' at all it 'works' mostly by coincidence as it
is relying on a non-standard extension wherever the - if-else - is
effective, and where the FunctionDeclaration are unconditionally acted
upon the result must only 'work' due to the order in which the two
declarations appear.
Of course the conditional creation of function objects is trivial in
javascript in a way that fully conforms with the ECMAScript
specification, and so in a way that can be expected to be fully
cross-browser and consistently executed in ECMA 262 3rd Ed. implementing
environments. Such code would be something like:-
var Hash = Class.create(Enumerable, (function() {
var each;
if (function() {
var i = 0, Test = function(value) { this.key = value };
Test.prototype.key = 'foo';
for (var property in new Test('bar')) i++;
return i > 1;
}()) {
each = function (iterator) {
var cache = [];
for (var key in this._object) {
var value = this._object[key];
if (cache.include(key)) continue;
cache.push(key);
var pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
}
}
} else {
each = function (iterator) {
for (var key in this._object) {
var value = this._object[key], pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
}
}
}
...
- replacing the 'syntax error' FunctionDeclaration with Expression
Statements where a Function Expression is assigned to an Identifier. The
result is fully ECMAScript standard and so will 'work' consistently in
all past, present and future ECMA 262 3rd Ed. conforming
implementations.

Why has a library not been written this way? Obviously it's not your
responsibility to do it, or to even know the reason why it hasn't been
done thus far, but if so many people are in error, and it causes you
any distress, it would behoove you to write one, or at least begin
one. Perhaps set up a project? Clearly you care a lot about this
subject, and have invested much time in it. This is just another
avenue by which you can participate in -- and even shape -- the future
of how javascript is used.


It is simply the case that anyone knowing javascript would have written
the original code in this final form. So would not be writing code that
functioned purely by coincidence but instead they would be programming.
The problem with the way this sort of ignorance of javascript results in
code that only works by coincidence is highlighted by browsers like
Opera. Opera currently acts like JScript, and unconditionally acts on
the FunctionDeclarations out of their (otherwise syntax error) context
but while Opera has an ECMA 262 conforming javascript implementation,
they also aim to emulate JavaScript(tm), and so may introduce
JavaScript(tm)'s FunctionStatement extension at any moment. And so code
that works by coincidence because of the order of the
'FunctionDeclarations' may find itself suddenly conditionally evaluating
FunctionStatements with any next version of Opera, and what these
branches do in that versions of Opera may be totally inappropriate.

So this is the browser's problem. They are too permissive. But if you
think about it, if 90% of people do something one way, and that way
doesn't conform to "the standard" (in this case, ECMA), doesn't the
way most people do it BECOME the standard? It may be horrific in its
implementation, syntax, whatever, but so is HTTP. So you either adapt
and use it, or try to make change.
The Prototype.js approach results in code that cannot be expected to
work in any more browsers than those in which it has been demonstrated
to 'work', and so cannot even be expected to 'work' with the future
versions of that those browsers. This cannot be a viable approach to
creating cross-browser code, and it does not.

Again, this may be the browser's fault then. Bear in mind that browser
developers do have to cater to existing web pages, and have all sorts
of testing to try to ensure that nothing breaks in future versions. I
highly doubt that just because a page doesn't conform to ECMA
standards, the browser developers will say "screw that web page, if
they don't follow ECMA they don't get a proper rendering in our
browser." This may work if the percentage of "bad" web pages were
vanishingly small, but hey, this is the real world where people are
stupid and market share is of vital importance to a browser's
continued existence. I'm not saying I'm encouraging bad coding, or
stupidity, but I'm being a realist. Once all market share is captured,
THEN you can begin to gradually enforce whichever standards are the
best. But until then, it's a free-for-all.
That is quite a bit of writing in order to demonstrate that the authors
of Prototype.js don't know javascript. Similar demonstrations are
possible for bad design, ridiculous inefficiencies, avoidable bad
practices and much else besides, but I don't have time right now so you
will have to look them up in the archive.

I truly do appreciate your perspective. I did a little research on
you, and you appear to be a very intelligent individual, although (and
I don't mean to be destructively critical) a bit of...

read more >>

I think the idea here is looking at the code is a good idea.

There will always be bugs. (browsers are a good example) Some bugs you
can live with, others are too unacceptable.

Mistakes and misconceptions are different.

Looking at code can show how the author thinks. Mistakes are one
thing, but when a script is written with misconceptions, well, it kind
of makes you look sideways at the script.
 
V

VK

I would tell you that your intelligence level is beginning to remind me
of VK, but, I don't want to insult VK like that so I won't.

You mean that VK needs a special profoundly thought insult, not a
simplified spontaneous one? :)
 
V

VK

If telling PointedHead that he is acting like you is an insult to you,
that means he is acting worse than you.

So is it a compliment to me? OK, but also can be read as an insult to
PointedEars (or anyone else in the future): "You are worser than VK" -
so "really ground bottom". A too complex statement for simple minds
like mine :)
 
V

VK

Don't get your hopes up :)


You are beginning to grasp it.


I am proud of you. It only took you three posts to figure that out.

Oh... But from the other side "there are people worser then you, VK,
so be proud of"; but from the other side "you're getting worser than
VK, PointedEars, so try to shape up"; but also can be read as ...
Did you you ever tried for a White House PR representative? You would
pass the sort out tests for sure.
:)

</OT>
 

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,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top