December 2011 Mailbag

By  on  

I get loads of questions each day so I decided to take a few moments to answer your questions about JavaScript, Dojo, MooTools, jQuery, and more.

How did you get so good at everything you do? How did you practice without feeling like you wasted time?

I'm the first one to say that I'm not good at everything; I'm definitely not. One thing I am, however, is persistent when I really love something. I love working with HTML, CSS, JavaScript, XHR, etc. so I spend loads of free time experimenting and trying to master the best techniques. I love every minute of it, and you can only improve that way. I'm not particularly interested in PHP anymore, so I tend to not enjoy spending time with the language, and thus have a hard time improving. My advice at getting good at something is to love it; when you love it, you do whatever you can to be great!

The only time I feel like effort has been wasted is when I wasn't interested in the topic enough to begin with; over the years, I've learned to stop working on a blog post when I stop caring right away. If I think others will find it interesting, I usually put forth the effort to complete it. I also keep the mindset of "if it will save another developer time and hassle, complete it for the common good." That's what this blog was founded on: paying it back.

What technology stack do you use for unit testing JavaScript?

Since I spend 40-50 hours per week work on enterprise-level Dojo applications, I work a lot with DOH, the Dojo Toolkit's unit testing framework. DOH allows for basic functional tests, performance tests, and even synthetic event testing with the DOH robot (which is essentially a Java Applet controlled by a JavaScript API). And since the Dojo Toolkit itself is tested with DOH unit tests, the API is very similar and writing unit tests can be fairly quick. Since Dojo relies largely on Deferred, a special doh.Deferred resource is available for easy testing of those.

Recently, however, my colleague Bryan Forbes created eventd, a synthetic event testing framework for use with Dojo. What I like most about eventd is that it creates synthetic events without the need of the DOH robot, so you don't need to worry about Java quirkiness. Bryan's working hard to remove eventd's Dojo dependency, and if eventd becomes fully library agnostic, eventd should be used by everyone.

One thing to point out quick: you can use DOH with any library, and I recommend you try it!

In what situations would you use Dojo, Mootools, or jQuery (if at all?); in what environment do they shine most?

I get this question all the time. Here's the quick answer:

I recommend using the Dojo Toolkit if you're building an advanced or enterprise level web application, or you think your application could become enterprise level. I also recommend using Dojo if your application will be UI-heavy (because the Dijit UI framework is amazing!), uses advanced IO (data stores, lots of XHR, JSONP, etc.), or charts or vector graphics will be used. Dojo will of course work on any size website, but the toolkit really shines when it comes to large scale websites.

I recommend using MooTools if you have a small to medium-sized website (...a non-Dojo site). MooTools packs a ton of power into a small Core package and is supported by many top-class More classes. These resources serve to empower the JavaScript language. Beyond the resources provided by the MooTools team, there are thousands quality plugins within the MooTools Forge, so if your application suddenly needs a new feature, there's a central location to get that plugin.

Both are extremely modular and teach great coding practices. They're both efficient, extendable, and written by brilliant JavaScript developers.

As for jQuery, I don't have a recommendation for when to use it. Nothing against jQuery, but I've never needed to go outside of MooTools and Dojo. No need. #MoojoFTW

Which PHP framework do you prefer?

To be completely honest, I tend to hate PHP frameworks. Why? They're usually over-abstracted, slow as hell, and difficult to debug. I've always found creating my own "mini-framework" as the best option, and then modify and add functionality as the situations come up. That way I have complete control over everything that's being loaded.

PHP frameworks are nice in that there's usually a community behind them, loads of plugins are available, and they have sexy names. I've recently used the Yii PHP framework and if you really need some, I recommend giving it a try. It seems much more lightweight that other PHP frameworks I've tried.

Where do you find the time to blog?

Most of my posts are written on weekends while I watch European football (not Arsenal games, where I pace around my living room for 90 minutes). Weekends provide me time to experiment without being interrupted. On the rare occasions that I'm compelled to write during the week, I grab a bottle of wine and my wife is much more understanding.

Recent Features

Incredible Demos

Discussion

  1. juanfer

    Could you on upcoming post if possible provide an example on how to test javascript, im currently using JsTestDriver and as a total noob i have some difficult setting up test.

    ps: Man-U #Chicharito14!

  2. Alex

    Its funny David, I do the same kind of pacing when watching the Gooners. But we are doing a lot better. I really want Ashavin to wake up though !!!! Have a good Xmas and thanks for all the great gems!!!

  3. I’ve been a big jQuery user for a long time and have used it for all sizes of projects, including enterprise level. What I love about it is the simplicity it provides while remaining robust in it’s abilities. It’s also quite modular in that there is a separate library for jQuery UI, and jQuery Mobile, among others. My favorite thing is the huge community behind it and the sheer amount of plugins available. Any time you need a new feature you just do a google search and you’re likely to find several plugins that do it for you.

    I am interested in checking out Dojo though because it seems to bundle all of the features of jQuery into one library. If they achieve this without bloat in the library that would be very nice.

  4. What caught my eye in this blog post was the statement about jQuery. Years ago, I started out with mootools (and actually used it as framework for the authoring side a large CMS) and can say with honesty that it was a great framework that deserve respect and recognition. The Class approach was nice to work with.

    However, as the CMS platform is based on .NET and jQuery tends to be really popular here (well, and because I felt that the development of the supported version of mootools was on the decline), I decided as part of a major rewrite of the UI to use jQuery as the framework of choice. Today, almost finalized with the rewrite, I’ll say that jQuery provides a really elegant API on top of the DOM as well as a really powerful and flexible widget API – and that’s all I need. Most of the classes I wrote for mootools was pretty easy to translate to jQuery widgets (including extending widgets and so on which tends to be a common thing mootools developers strike as being special for mootools).

    Atleast from the size of the CMS platform I think it was more elegant (and fun, actually) to work with jQuery, but I also realize that jQuery only takes you so far; however, a skilled javascript developer would be able to leverage jQuery in many clever ways, just like those other developers using mootools or Dojo. I feel it’s more transparent to express ideas in javascript (with jQuery), than with mootools, but I realize there are other kinds of applications that require a different framework from what I need.

    Closing off, I’d like to express my respect for the passioned people developing the frameworks. You’re priceless.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!