After all these posts, I'm none the wiser: what is the problem these
libraries are trying to solve?
The goal of any library/framework/layer/abstraction is to simplify the
solution to one problem, so it can be used as a foundation for solving
a bigger problem.
Browser scripting can be complicated, marred by over a decade of
browser hacks, quirks, bugs, and non-compliant behavior. If a person
is required to understand, solve, and code for all these problems that
have been built up for years, they are unable to focus on bigger
problems.
Imagine if, every time we wanted to make an ajax call in js, we needed
to worry about browser threading, the OS we were on, the network
stack, handling tcp/ip correctly, handling dns, all the way down to
the ethernet layer. It would be an insurmountable problem. Thankfully,
all those layers have been abstracted away for us. We have just a few
concerns to deal with ajax, since we have to solve for a few different
browser conditions and quirks.
Along with all those layers of abstraction comes trade-offs.
Certainly, performance is reduced by each layer. There may be bugs and
quirks in each layer. Our ajax call may fail not because we coded the
js incorrectly, but because a DNS bug caused the lookup to fail. But
there is no way we would ever think of re-writing all these components
to be more technically correct. Even if we knew the faults and knew
how to code them better, it would not be practical. Accepting the
stack of layers under you - the good and the bad - allows you to focus
on higher-level problems.
Now, writing applications for the web has developed to a degree that
authors no longer want to deal with the lower-level problems of
javascript, browsers, the DOM, etc. They may want to just display an
in-page dialog that blocks the rest of the UI, for example. It seems
like a trivial task, but in reality it's a complex problem.
A library simplifies the problem, so instead of having to understand
and solve 100 scripting issues, they now just have to understand a few
API calls. And they can then afford to combine even more complicated
behavior together to create something that would have otherwise been
too complex to create.
Obviously, the library introduces a layer of complexity that comes
with its own problems. It may be less efficient, or may not work in
some browsers, or may have other issues. But these are the trade-offs
for having a large, unmanageable problem reduced to a smaller,
manageable one. Just as there are many trade-offs in the long stack of
abstractions between your js scripting environment and the bits in the
hardware that is driving it all.
Surely, it is up to the developer to decide whether a library is a
good layer of abstraction to introduce. If it solves a great number of
problems and allows them to focus on bigger issues, then that is good.
If it introduces new bugs or incompatibilities or problems, then it's
important for the user to be aware of exactly what they are
sacrificing, and to decide if it's worth it.
Some people are so attached to this specific technology - their ego so
caught up in understanding this layer better than anyone else - that
it's frustrating for them to see anyone "abstract away" their
knowledge. These people fear the day when the js layer is abstracted
away, because then their expertise is no longer needed. They can point
out the faults in specific libraries all day long, but they lack the
vision to see that _every_ layer eventually gets abstracted away. It's
how technology advances.
JS Libraries, as a way to abstract away the problems with browser
scripting, may not be the *best* solution. But it is one solution, and
it works very well for many people. I think it's great to argue for
different ways to abstract away the problem, and pick the option that
is best. But IMO, rejecting the abstraction altogether because of its
shortcomings is short-sighted. Web development will move on without
these detractors. Libraries will be used and improved, because people
don't want to have to deal with the whole nasty, confusing browser
scripting layer. They want it solved, at least to a degree that they
are comfortable with, and presented in a nicer, easier-to-use form.
That's what libraries like jQuery do, and that's why people so
overwhelmingly choose to use them.
Matt Kruse