Why should I eschew prototype.js?

N

nolo contendere

I've recently begun playing with prototype.js as well as
scriptaculous, and found both very helpful in developing web pages
with lots of pop. Modal boxes, SlideUp/Down, calendars, etc.

I've also recently ramped up my lurking and participation in this
newsgroup. There are some who advocate using prototype, and others who
are adamantly opposed to it. Are there any concrete reasons why I
should NOT use it? Is it inefficient? It seems that today's computers
have sufficient processing power to overcome most slowly implemented
solutions in javascript. And the benefits of being able to inject such
a wide variety of effects into a page (to me) far outweigh any harm.
 
G

Gregor Kofler

nolo contendere meinte:
Are there any concrete reasons why I
should NOT use it?

Since it won't foster any understanding of proper JavaScript programming
(or even use).

You'll run into problems sooner or later (because you'll combine
prototype with mooTools and jQuery and throw in another "framework" for
good measure, and all those "frameworks" have their individual
shortcomings).
You will end up asking another one of those "my this-or-that form
element doesn't work the way I expect it, why?" questions.

And all the advice you'll get, is to look for help elsewhere.


Gregor
 
N

nolo contendere

nolo contendere meinte:


Since it won't foster any understanding of proper JavaScript programming
(or even use).

You'll run into problems sooner or later (because you'll combine
prototype with mooTools and jQuery and throw in another "framework" for
good measure, and all those "frameworks" have their individual
shortcomings).
You will end up asking another one of those "my this-or-that form
element doesn't work the way I expect it, why?" questions.

And all the advice you'll get, is to look for help elsewhere.

This argument can be applied to any library of functions. The harm
here is that by not using a library, one must constantly reinvent the
wheel. If I get a job as a front-end developer, I'll likely inherit
some code. Whether the code was homebrewed by the previous developer,
or adopted by him/her, it's possible that coding I do for projects
going forward will conflict with this library, and I'll have to debug.
At least with a library that is more widely adopted, and for which
there is some documentation, I'll have better tools and more resources
for doing that debugging.

As far as not fostering understanding of Javascript, that's not what
libraries are for. It's my responsibility as a developer to learn the
language.

I can definitely see your point that it could be a crutch though, and
could enable bad programming practices as well as laziness in
understanding the language. If that's the primary disadvantage, I
won't worry about it. I've just seen in some poster's tags that
prototype was written by people who don't understand javascript, but
there was no evidence to support that claim.

Thanks for your response.
 
G

Gregor Kofler

nolo contendere meinte:
As far as not fostering understanding of Javascript, that's not what
libraries are for. It's my responsibility as a developer to learn the
language.

Discussing the *use* of JS libraries is not the focus of clj.
I can definitely see your point that it could be a crutch though, and
could enable bad programming practices as well as laziness in
understanding the language. If that's the primary disadvantage, I
won't worry about it. I've just seen in some poster's tags that
prototype was written by people who don't understand javascript, but
there was no evidence to support that claim.

Google might help - the problems (or - for some - the lack of these)
with these frameworks have been discussed in this NG several times.

Gregor
 
T

Thomas 'PointedEars' Lahn

nolo said:
[...] There are some who advocate using prototype, and others who
are adamantly opposed to it.

You will observe the individuals who recommend against Prototype.js usually
to be more knowledgeable about the language(s) than the individuals who
recommend in favor of it. That should account for something.
Are there any concrete reasons why I should NOT use it? Is it inefficient?
Yes.

It seems that today's computers have sufficient processing power
to overcome most slowly implemented solutions in javascript.

You are mistaken. First-world high-end computers and Internet connections
are not the standard to develop for on the Web, at least they should not be.
Besides, efficience is not restricted to runtime efficience, and efficience
is one of the lesser problems with Prototype.js.
And the benefits of being able to inject such a wide variety of effects
into a page (to me) far outweigh any harm.

The harm comes from another direction.


Ceterum censeo Prototype.js esse delendam.[1]

PointedEars
___________
[1] Belated thanks to Evertjan. who by his correction put me on track
to find out that the English verb "(to) delete" is derived from
the Latin verb "deleo" ([to] destroy).
 
N

nolo contendere

nolo contendere meinte:


Discussing the *use* of JS libraries is not the focus of clj.

I suppose not--as i stated previously, I'm new here. However, just
because it's not the focus doesn't mean that there can't be ancillary
discussions about it.
Google might help - the problems (or - for some - the lack of these)
with these frameworks have been discussed in this NG several times.

Did so.

I had not realized prototype.js was such a hot topic, or that just by
bringing it up I might invite myself to being viewed with immediate
hostility, or, at best, a standoffish neutrality rather than with a
friendly smile and an offer of a helping hand. Still, better than what
some newbies get at c.l.perl.misc...;-)

After reviewing some threads about this subject, I discovered an
enlightening one:
http://tinyurl.com/yps5l9

Thanks.
 
G

Gregor Kofler

nolo contendere meinte:
I had not realized prototype.js was such a hot topic,

I'd say it is anything but "hot" on clj.
or that just by
bringing it up I might invite myself to being viewed with immediate
hostility, or, at best, a standoffish neutrality rather than with a
friendly smile and an offer of a helping hand.

People using prototype are rarely interested in writing their own
scripts, particularly writing them properly. However, that's what a lot
of people reading clj want to do. I once got in touch with prototype
about two years ago - the size of library and the then complete lack of
documentation drove me to writing my own lean libraries.
Still, better than what
some newbies get at c.l.perl.misc...;-)

That's usenet. If you want to be caressed you have to resort to web
forums, I suppose.

Gregor
 
S

s0lnic

nolo said:
Are there any concrete reasons why I
should NOT use it?

No, there aren't, unless you're able to write something better then
jQuery/Prototype/YUI/Mojo/whatever or you just want to have your own
library and you have enough time to do this. If you're creating webapps
with a rich UI then you definitely need a JavaScript library.
Is it inefficient?

No, it's not.
 
T

Thomas 'PointedEars' Lahn

s0lnic said:
No, there aren't, unless you're able to write something better then
jQuery/Prototype/YUI/Mojo/whatever

Almost anyone is able to write something better than those, with *maybe*
the exception of YUI.
or you just want to have your own library and you have enough time
to do this.

That is an entirely different matter, of course.
If you're creating webapps with a rich UI then you definitely need
a JavaScript library.

But not necessarily a library written by people who don't have a clue
about what they are doing.


PointedEars, with a fitting random signature
 
N

nolo contendere

No, there aren't, unless you're able to write something better then
jQuery/Prototype/YUI/Mojo/whatever or you just want to have your own
library and you have enough time to do this. If you're creating webapps
with a rich UI then you definitely need a JavaScript library.


No, it's not.

Thanks Piotr. That's the second time you've helped me :).
 
M

Matt Kruse

There are some who advocate using prototype, and others who
are adamantly opposed to it.

There are a few long threads (one recently) about the concept of
libraries and philosophies about how javascript should be developed.
People usually fall somewhere in the spectrum between "use a library
like prototype and do it all that way" and "never use a general-
purpose library - write your own code to meet the requirement at
hand".

Where you land depends a lot on your javascript knowledge and
experience, your goals, priorities, and context. If you are
comfortable with the idea of using a general-purpose library, then
that whole discussion can be tabled and instead you can focus on which
library you should use and how you should best use it.
Are there any concrete reasons why I
should NOT use it?

Stylistic preferences would be one. I don't like its emphasis on
classes, inheritance, etc. For me, the API is too large and complex -
it tries to do more than I want it to. And I found it hard to use to
just add some quick effects or helper functions to an existing page.
I've never looked into the internals to judge it technically.
Is it inefficient?

Certainly more inefficient than using core DOM functions and built-in
javascript functionality. But probably not enough to make a difference
in most cases. If you get into heavy UI stuff, general-purpose
libraries tend to slow down, in my experience.
It seems that today's computers
have sufficient processing power to overcome most slowly implemented
solutions in javascript.

Depends on your target audience.
And the benefits of being able to inject such
a wide variety of effects into a page (to me) far outweigh any harm.

Again, it comes back to your requirements and priorities. If you want
to support as many users and browsers as possible, trying to create a
slick client-side UI with lots of effects and stuff will kill some
people.

I think it's best to read the arguments on both sides to become more
informed. Then consider all the factors in front of you and come to
your own conclusion about whether a javascript library will be helpful
to you.

Matt Kruse
 
N

nolo contendere

Again, it comes back to your requirements and priorities. If you want
to support as many users and browsers as possible, trying to create a
slick client-side UI with lots of effects and stuff will kill some
people.

True, but you can't please all the people all the time. I'm testing
out my code in IE 6, FF 2.0, and Safari 3. That covers enough area for
me. Also, this is an internal site, so I can be reasonably sure of the
consistency and specs of the machines that will be used to view the
site.
I think it's best to read the arguments on both sides to become more
informed. Then consider all the factors in front of you and come to
your own conclusion about whether a javascript library will be helpful
to you.

Sage advice for any topic.
Matt Kruse

During the course of my research into the original question, your name
popped up a few times. I checked out your site, and also noticed that
the clj FAQ guy, Randy, had your Best Practices link in his sig. I
don't know too much about your credentials, but you at least seem to
try to help people rather than latch on to some trivial technicality
or misspelling or minutia and harp on it, for which you get my
respect.

I also noticed that you wrote several Google Gadgets--they look pretty
neat, although the target audience seems to be pretty advanced users
(read: hard-core geeks). By this I mean that the gadgets are very
customizable, which is a good thing, but the number of configuration
options may dissuade it's adoption by the general masses.

Anyway, thanks for your input. It was constructive.
 
M

Matt Kruse

I also noticed that you wrote several Google Gadgets--they look pretty
neat, although the target audience seems to be pretty advanced users
(read: hard-core geeks). By this I mean that the gadgets are very
customizable, which is a good thing, but the number of configuration
options may dissuade it's adoption by the general masses.

True, but I wrote them all for my own use. My iGoogle page is heavily
customized and filled with tons of feeds and info. I make the gadgets
available to the world because I never know who might find them
useful :)

Matt Kruse
 
G

Gregor Kofler

nolo contendere meinte:
True, but you can't please all the people all the time. I'm testing
out my code in IE 6, FF 2.0, and Safari 3. That covers enough area for
me.

It's not a compatibility issue (at least with a decent library) -
webpages should always provide a fallback for people without JS. JS for
the eye-candy and the enhanced usability, but not for the core
functionality, but then...
Also, this is an internal site, so I can be reasonably sure of the
consistency and specs of the machines that will be used to view the
site.

....YMMV.

Gregor
 
S

s0lnic

Thomas said:
Blind leading the blind.

Why? There are no perfect tools, I'm sure you know that. Prototype helps me
a lot in my everyday work, there are many things which bugs me, but it's
getting better and better. I don't have any serious problems with it, its
current http://www.prototypejs.org/api is very useful, its performance is
just fine, it resolves many common crossbrowser issues which every web
developer has to deal with (sooner or later). I started using Prototype
about 1.5 year ago, before that I was writing all my JavaScript without a
use of any other library and it was sometimes really painful (back then
IE5.5 had to be supported ;P). Maybe you, JavaScript masters with zillions
years of experience, have better alternatives, maybe you have written your
very own libraries, which are better then anything else - good for you
then! I wish I had enough time to do the same, but I don't and I'm using
what's available, and Prototype IS a good option, maybe other libs are
better (jQuery looks very promising), I don't know, haven't used them in
any real project yet. The fact is that I DID use Prototype and there are
MANY working applications which are based on Prototype, and you know what?
People use these apps, and they really like them, so what's the problem?
No, stop, don't answer - Prototype creators don't know what they are doing,
they know sh*t about JavaScript, this library should be destroyed.
Whatever, man.

Cheers and EOT
 
N

nolo contendere

nolo contendere said the following on 11/12/2007 10:44 AM:


That is a backwards issue that has been in computing for over 30 years.
"I don't have to write efficient code because computers are fast enough
to compensate for it."

Sure, taken to either extreme, the efficiency of code can either be
the most or least important thing. Practically speaking, it doesn't
make sense to spend years profiling and tuning code to get the
absolute best performance out of it. And yet it also doesn't make
sense to use algorithms that are O(n^3) or worse. I didn't mean to
blithely assert that I can be lazy and not have to consider the
performance of my code, I was looking at it more from an order of
magnitude scope. My earlier question could have been better phrased
"Would using prototype.js rather than the native DOM/javascript
functions impose a cost that would be orders of magnitudes greater?".
If not, then I wouldn't want to spend time micro-optimizing.

I have some expertise in Perl, and like to write efficient code, but I
realize that if performance was THE most important factor, I wouldn't
write code in Perl.
 
R

Richard Cornford

nolo said:
I've recently begun playing with prototype.js as well as
scriptaculous, and found both very helpful in developing
web pages with lots of pop. Modal boxes, SlideUp/Down,
calendars, etc.

I've also recently ramped up my lurking and participation
in this newsgroup. There are some who advocate using prototype,
Here?

and others who are adamantly opposed to it. Are there any
concrete reasons why I should NOT use it?

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

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.

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.

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.

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.
Is it inefficient?

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.
It seems that today's computers have sufficient processing
power to overcome most slowly implemented solutions in
javascript.

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.
And the benefits of being able to inject such
a wide variety of effects into a page (to me) far
outweigh any harm.

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

Richard.
 

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,135
Latest member
VeronaShap
Top