4

I'm not a huge fan of the JavaScript frameworks that are out there today. I think a lot of the libraries could be written better, are chosen for a project because of favoritism rather than understanding the requirements of the problem at hand, and some JavaScript developers come to depend on them too much to the point where they are jQuery or dojo programmers, not JavaScript programmers. Alas, that is one person's opinion and the fact is JavaScript frameworks are a part of life. So, here's a new take on an old question: Which JavaScript framework is the least evil? That is to say, which library most closely adheres to best practices? Considering jQuery for a moment, it employs browser sniffing and doesn't use new for constructors. It is very popular and some may judge it the best by some standard, it disregards what has come to be accepted as best practices in those cases.

Edit: Please just don't say jQuery or YUI or dojo or whatever. Please say which but also provide examples.

Timothy
  • 4,630
  • 8
  • 40
  • 68
  • 7
    @Timothy `I think a lot of the libraries could be written better` - write one then we're all gonna be happy – ant May 18 '10 at 14:51
  • @Timothy, I like jQuery - but that's only because it has a good user-base and community behind it. Making it less evil than say... YUI :) – Barrie Reader May 18 '10 at 14:52
  • @Timothy - "I think a lot of the libraries could be written better" majority of open source projects are started with this statement – Andrey May 18 '10 at 14:55
  • 1
    jQuery does *not* use browser sniffing but rather provides support for *developers* to employ browser sniffing if they so choose (see http://api.jquery.com/jQuery.browser/). Also, jQuery is itself implemented as a constructor function (see http://stackoverflow.com/questions/1853223/check-if-object-is-a-jquery-object/1853246#1853246 , ie it *does* use `new`). – Crescent Fresh May 18 '10 at 14:55
  • Please define "best practices" – Matti Virkkunen May 18 '10 at 15:00
  • jQuery provides browser-sniffing, but advises you not to use it. Internally it uses only feature-sniffing. And it doesn't really have any objecty stuff for which `new` would be appropriate. So I don't think these are good reasons to hate on jQuery. – bobince May 18 '10 at 15:06
  • ...no, far better reasons would be its far-too-overloaded interfaces (making it hard to read and determine which method is being used possibly-by-accident), its confusing mixture of chain-style methods (so you're never quite sure whether you're getting a returned object or the original), the lack of a select-one method (so you only have select-many, which won't generate an error when your selector fails to match anything), its encouragment of string-hacking selectors and HTML, and in particular its own appalling string-hacking in anything to do with HTML handling, through the `clean` function. – bobince May 18 '10 at 15:07
  • 1
    I've never found a framework that isn't to some extent evil – Prototype 1.x is just as bad as jQuery, though in different ways – and I'm not convinced it's possible to make a framework non-evil. The nature of JavaScript and the DOM makes it difficult to add features in a clean way. And hell, plain JavaScript itself is pretty evil to begin with. – bobince May 18 '10 at 15:07

4 Answers4

6

Well - I used to be of the same view, never really used JS libs as - well, I can do it myself. But in my job I was forced to use Jquery.

Previously to that I would use Prototype and script.aculo.us and liked it because of its minimal injection into your daily workflow.

But saying the libs are evil isn't really something I agree with. Looking at the code of many libs, they are well written and concise. They generally fit all browsers without bugs.

That's the real reason to pick up these frameworks - to implement code you could create, only better. I would never be as bold to state, I could do as thorough a job as 100 contributor the frameworks have.

Additionally, its the amount of time these JS libs swallow for you. If I can shave 3 days off creation and debugging of a project - because someone has happily done the exact same thing for me, that's great! Then hopefully I can give back on day.

I don't believe there are evil frameworks, just different.

Glycerine
  • 7,157
  • 4
  • 39
  • 65
1

Lol. That surely is subjective, but anyways...

Personally I think YUI is the least evil as it has Douglas Crockford himself advocating it. ('nuf said)

Although, I don't really think that other frameworks are necessarily evil...

jQuery seems to go for easiness of use (just include jquery.js, copy-paste some samples, hack a little bit and you're done).

Dojo goes for completeness (for what I can see) implementing many utilities (much like apache commons for java), and a broad list of widgets, grids and charts.

Then there's Prototype which I'm not really fond of it since it modifies the native objects.

There's also Ext JS that has lots of widgets and visual components to build full fledge applications, but I'd stay away...

DayTimeCoder
  • 4,294
  • 5
  • 38
  • 61
Pablo Cabrera
  • 5,749
  • 4
  • 23
  • 28
-1

My vote is for jquery. With noConflict() you can use multiple versions on the same page, easy learning curve with css selectors.

derek
  • 4,826
  • 1
  • 23
  • 26
-2

MyLibrary

RoToRa
  • 37,635
  • 12
  • 69
  • 105
  • 2
    It calls itself an "Ajax library". I wish there was a -1 button for websites – Matti Virkkunen May 18 '10 at 14:55
  • A) It doesn't. It says its a "browser scripting library (also known as an Ajax library)" referring to the fact that many people (who don't know better) consider "JavaScript library" and "Ajax library" to be the same. And as with many frameworks Ajax is only a small part that can be left out if not needed. And B) What is so bad about "Ajax library"? – RoToRa May 18 '10 at 15:02
  • "Ajax" has come to mean a dozen different things, mostly due to mis/overuse. I prefer to avoid the term altogether. Let's leave buzzwords for marketing. – Matti Virkkunen May 18 '10 at 15:04
  • I completely agree with you. And IMHO the wording on the site, the structure of the library and the presence of the builder acknowledges exactly that. – RoToRa May 18 '10 at 15:10