A letter to the .NET magazine

Staring keenly at a stack of magazines, I hazard a gaze towards the computer section and lay my eyes upon the newest cover of my sworn enemy, the .NET magazine. Its luring front-page convinces me that it deserves my consideration.

I buy it without looking inside. I want to reserve the surprise for later.

Now sitting in the lounge at London Gatwick Airport, I whip out the magazine and rush to a JavaScript article. I can’t wait. It’s about jQuery and I just know that they’ve gotten their act together since previous encounters. I’m sure this article will contain the best in jQuery techniques and JavaScript best practices.

Well, .NET, now I’m sitting here with the unfortunate duty to inform you of my unsurprising disappointment.

The truth is I expected nothing more from you.

Please turn to page 80 of issue 205 and pay special consideration to the following reservations of mine:

The author doesn’t mention the possibility nor the applicability of creating a jQuery plugin instead of the single globally defined function ‘drawerToggler’. What’s wrong with this? Well, the function happens to contain functionality that could be abstracted to deal with arbitrary sets of nodes and is therefore suited to jQuery’s plugin mechanism. I would understand if at least a mention surfaced, but nothing.

This is certainly not the worst of it though.

The function itself:

function drawerToggler() {
    $('#theme-drawer').slideToggle("normal", function(){
        if ($('#theme-drawer').is(":visible")) {
            $('#wrapper').css("margin-bottom", "150px");
        } else {
            $('#wrapper').css("margin-bottom", "20px");
        }
    });
}

Where it’s being called:

$(document).ready(function(){
    $('.drawer-toggler').click(function(){
        drawerToggler();
    });
});

This function is called within the click event handler for any element with a className containing drawer-toggler. Since it’s getting called on every click, and the elements selected within the drawerToggler do not change between calls, it would be logical to select and “cache” the DOM object references beforehand, and then the function could use these DOM references instead of continually (and redundantly) re-querying the DOM on every single call!

The function itself contains some redundant code too. The ‘theme-wrapper’ to which the slideToggle method is applied, is then re-queried within the callback. Apparently unbeknown to the author, this very element can be accessed via the ‘this’ keyword within the callback function — there is absolutely no need to re-query the DOM for #theme-wrapper!

This isn’t just a case of my preferences versus the author. There are established best practices in the jQuery community and as one of the industry’s top publications you should be providing not only good advice but near enough the best advice according to current industry practices and standards.

Now, I could stop, but the reign of nonsensical JavaScript programming continues.

On page 82, along with the insistence of using $(this).attr('rel') instead of the terser and faster DOM equivalent, this.rel, the author insists, again, on re-querying the DOM for unchanged elements within the click event handler for all anchor elements within #themes-wrapper!

There’s a few more specific issues I’d like to raise but I feel I’ve already made my point in regards to the obvious inadequacy of the article itself.

The article specifically says that it’s geared towards developers with an intermediate-level understanding of HTML, CSS and JavaScript. If you want to further the knowledge and understanding of these developers then you must, as reason would dictate, have a teacher that presents a higher-than-intermediate understanding of these technologies.

Before you suggest that I write an article to amend previously made mistakes (“Instead of complaining write your own article.. blah blah blah”) I’d like to let you know that I will do no such thing. It is your responsibility to find the best authors and the best content featuring the topic at hand.

I write this letter not only because I care, but because I am desperately worried, as are many others, about the state of jQuery within the JavaScript community, and more generally the lacking understanding that is slowly rotting the core principles of JavaScript from under its feet. Let the ignorance stain the ranks of beginners and hobbyists, as it always has and always will, but let it not protrude into a publication that claims to encapsulate the ever-changing essence of the web industry. Stop pandering to the lowest common denominator and be the best!

I realise that, from a monetary perspective, such concerns are likely to be lower on your priority list than getting that new coffee machine for your staff, but for the love of what you claim to stand for, prove to me that you are more than what I dare think you may just be — another profit-based publication whose sole concern is the quantity of its readership rather than the quality of its content.

If you’re going to publish articles relating to JavaScript then you’re going to have to tighten your belt and get to work. It’s not a playground. Currently, you’re only serving as a catalyst to the ignorance that a magazine such as yours should be out to destroy.

If you think this letter is not worthy of your consideration, then discard it as one of many (no doubt) complaints, for I am only too happy to accept that I’m right about you!

Prove me wrong. I dare you.

JAMES PADOLSEY