Archive for the ‘General’ Category

Dear .NET

Posted in 'General, JavaScript' by James on July 26th, 2010

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.

Me…

Posted in 'General, My Life' by James on July 13th, 2010

Okay. For once, I’m going to say what I actually think on this site of mine! I’ve done it to a degree before but I got frequently hushed by the few people that see anything but neutrality as a weakness or a threat. I’m only human, and I have some damned opinions. So here they are!

Be prepared for mildly offensive rhetoric and inappropriate usage of the ellipsis and exclamation mark!!!

  • I think this universe is simply awesome. We’re quite tiny when everything is put into perspective. Heck, we’re just one form of life, on one planet, in one star system of hundreds of billions of star systems in this galaxy alone (which itself is accompanied by hundreds of billions of other galaxies), and yet some people still have the arrogance to feel that the human race is at the centre of the whole universe! Our wonderful yet miniscule existence is aptly covered in this beautifully poetic video from the late Carl Sagan.

  • I think inline documentation, like that made possible with JSDoc, makes code ugly and unreadable. I want to see the code, and that’s all!
  • I love the outdoors. I envy people that have jobs outside. And I don’t mean outside on the street cleaning up human sewage. I mean outside in the real world — the places that we haven’t yet destroyed.
  • I think heavy UI abstractions like ExtJS totally take away all of the fun, excitement and challenges that should form a central part in any programmer’s role. To me, it looks like a product built for business people, and business people rarely understand the motives and desires of programmers — they only understand a couple of things: profit margins and economic viability.
  • I’ve yet to sit in an office chair that won’t make my back hurt like hell after eight hours.
  • I don’t believe in a God. I also don’t believe in fairies or unicorns.
  • I get annoyed when people don’t realise the difference between believing that something doesn’t exist and rejecting the belief that something does exist, for it should be apparent that there is a huge difference.
  • My favourite comedians of all time are Ricky Gervais, George Carlin, Frankie Boyle and Bill Hicks (watch all the videos!).
  • I hate running, but I absolutely love cycling!
  • I don’t understand Node.js. I really did try, but it just ended up confusing me. I’m not a Linux wizz so installing it was trouble enough.
  • I think modern day advertising and marketing techniques are the bane of western society. Oh, and politicians!
  • I didn’t care for the World Cup, and I always find it amusing how people shout at the TV and put flags on their cars when it won’t have the slightest effect on the game itself.
  • I’m trying to become a vegetarian. Watch the documentary, Earthlings, and you’ll understand why.
  • Pixar made me cry. I don’t know how they did it…
  • I’d love to know how to play a musical instrument properly. Preferably the piano.
  • I think humans have a responsibility to stop using non-renewable resources, but I don’t think playing the blame-game is helpful. I also don’t think change will happen given the current political and economic powers that be.
  • I have a love-hate relationship with PHP. Doing most things is dead simple (which is great), but it’s such an ugly language!
  • Even after all this time, jQuery is still my favourite JavaScript library. It’s small, intuitive and doesn’t require me to adopt a new programming paradigm!
  • Other movies that have made me weep like a baby include The Stoning of Soraya M, Forrest Gump, The Champ and Pay It Forward.

Okay, that’s enough for today. Comment if you want. If you disagree with me on any of these points, then, GOOD! This world would be such a dull place without such varied opinions and people!

Questioning non UI events

Posted in 'General, JavaScript' by James on April 29th, 2010

Without UI events we’d be totally lost on the client-side — it is only via User Interface Events that we can know what the user wants to do. User-initiated events such as “click”, “mouseover” and “mousemove” are absolutely essential to upholding a user-centred experience and I want to make it clear that my quarrel is not with these types of events. Any event that gives us information about users’ intentions is a good event.

I feel that there are bad events too though — events that we feel we must utilise just because they exist — and we feel we must build into our APIs just because event-driven design dictates absolute submission to this way of thinking.

DOM mutation events

Every single time I’ve ever considered using a DOM-mutation event I’ve subsequently discovered that the problem can be better solved by re-architecting the codebase. The DOM2 mutation events aren’t well supported in less capable browsers but offer an interesting opportunity — to listen for document mutation such as attribute changes, node insertion and node removal.

This sounds cool and I’m sure your mind was buzzing with ideas when you first heard about these events, but have you actually encountered a situation where utilising these events is the only viable solution? If so, I’d love to hear it.

jQuery: Novice to Ninja

Posted in 'General, JavaScript' by James on February 26th, 2010

Sitepoint’s latest title is aimed at the average Front-end developer/designer and promises to teach her the intricate workings of the jQuery library. In fact, if we’re to go by the title, it promises to take her from “novice to ninja”. Let me be honest, I was originally skeptical of the book, but upon finding out that it was co-authored by the esteemed mrspeaker my mind was quickly changed.

jQuery: Novice to Ninja

As with any good book, the first chapter outlines what the subject matter is. The authors talk about jQuery itself and touch briefly on the DOM. You have to remember that this book is aimed at developers or designers that don’t really know that much about JavaScript, the DOM, or jQuery, so the book is accordingly written in such a way that it won’t confuse the pants off your typical photshop-wizz turned HTML/CSS guy.

So if you know JavaScript well, you might not enjoy this book — it will probably annoy you, simply because it doesn’t go into a huge amount of detail on what’s happening behind the scenes. But, for those that it’s aimed at, I think it does a pretty good job.

One thing that we have a problem with, in the jQuery community bubble, is the overzealous generation of redundant nomenclature. This book doesn’t fall short on this front. jQuery’s methods are referred to as “actions”.

The second chapter covers the most basic usages of jQuery, selecting stuff and doing stuff. It’s all innocent and simple — I like it. To keep the reader focused the authors have slipped in “A few tricks”. Among them is the popular add-a-class-on-mouseover, remove-it-on-mouseout.

Nearing the end of chapter two, the book has the following to say about the hover method:

Trying to learn Java

Posted in 'General, My Life' by James on July 22nd, 2009
Trying to learn Java

I’m off to University in just over a month and I thought it’d be a good idea to get a head start, academically. I’ve applied to study Computer Science, and, as only sense dictates, the first language we touch upon will be Java, the big brother of JavaScript… kidding; I can hear Crockford screaming! So, with all this spare time I’ve decided to learn Java, or, at least begin on the journey!

I downloaded Eclipse and the “Java runtime”, only, of course, to find out that I already had about 10 different Java runtimes already installed. I fired everything up and then stopped; I had absolutely no idea what to create… What can I say? The command-line doesn’t excite me! Yes, I know pretty much anything can be created with Java, even hardware-accelerated games, but all the beginner-tutorials out there only show you the monotonous command-line drivel.

I also purchased a book recommended by the University; I believe it’s the one we’ll be learning from in the first year. It’s called “Objects first with Java” and goes into a tremendous amount of (unnecessary?) detail; I haven’t really got past the first few pages. I’ll tell you something about objects; you’re never going to learn squat about them from tutorials or books. Yeh sure, you’ll get an idea about what they are but you’ll never appreciate the abstraction provided by OO language until you dive in.

Now, don’t get me wrong about this whole University thing; I am looking forward to the “experience” but I’m not exactly overly-excited about the impending course material. I haven’t even begun and I’m already finding it dull; I’ve no doubt that I’ll be pleasantly surprised though… I’m sure the first lecture will prove enthralling!

I’ll be honest with you; I’m only going to University because “that’s what one does after school”. Heck, most people go to Uni for exactly the same reason (they just don’t know it); it’s what’s expected of us. You can say what you want about it but essentially, University is yet another device used to extend and perpetuate the status-quo; i.e. us working and the government getting richer. I just can’t wait; out of uni with a load of debts and then into the monotony of a “career”. Eventually I’ll have additional burdens that will require monetary attention and before you know it I’ll be where most of the British upper-middle-class finds itself, paying off debts… living the dream!

Isn’t it amazing, I haven’t experienced any of this impending fate yet and I already have the capacity to be utterly dismissive and totally negative about it all! Here’s hoping the grass is greener!

Take a stand against IE!

Posted in 'General' by James on July 12th, 2009
Take a stand against IE!

I’ve got a great idea; let’s annoy the hell out of 75% of IE6 users by showing them a “you should upgrade” message, even though none of them have the actual capability to upgrade! Seriously, what a superb idea! It’s like having a “fly to work” sign instead of a train station, when everyone knows that only 25% of humans can actually fly!

Yes, a recent survey by Digg revealed that only one quarter of all IE6 users have the power to change. This minority is made up of two groups: those that simply don’t see a need to upgrade and those that prefer IE6 to other browsers.

So, without sounding too pessimistic, trying to get IE6 users to upgrade is almost entirely pointless! Your efforts would be better spent teaching 75% of humankind how to fly!

I haven’t really got a good idea; in fact, I’m equally as clueless as most of you… How on earth are we going to solve the IE problem, or, rather the “Microsoft” problem?

Have you ever read about that world record that was set when a bunch of people somewhere jumped up at exactly the same time? Speculation has it that the earth was temporarily knocked off its axis, which, consequently saved the earth from a massive meteor strike!? Well I haven’t, but I do have a similar idea that is almost guaranteed to work.

Imagine, if every single website on earth suddenly broke in IE – users of IE would be utterly confused and annoyed – there would be an epic stream of complaints battering every IT department this side of the sun! Eventually it would result in the demise of IE (all versions). So you see, it is possible! Together we can bring down IE, it just takes a tad of collaboration!

Rant: “Crappy comments”

Posted in 'General' by James on June 4th, 2009
Rant: “Crappy comments”

Okay, this really annoys me sometimes; you read a blog post or article, it was interesting, you scroll to the comments section looking for an interesting discussion regarding the content of the post but all you find is countless grammatical or technical corrections contributed by “helpful” readers!

For me, the comments section of a blog post is where users can contribute thoughts concerning the material covered in the post; not spelling mistakes, or a complaint about the site’s content. Apparently not everyone feels this way, because whenever I go to read the comments there’s always a few egotistical children leaving comments about the damn grammar!

Now, I’ve probably done it a couple of times in the past myself but I’ve stopped – I eventually realised I was only doing it to gratify my own needs; I wasn’t really interested in the grammatical correctness of any post – my ego just required a frequent pampering, apparently in the form of grammatical superiority.

Sometimes it may be appropriate to point out these mistakes; if the mistake will cause obvious grief to other readers who take heed from the post then by all means contribute your correction, but if it’s a tiny, barely-noticeable mistake then please keep it to yourself… or, if you feel your alter-ego “Grammar Nazi” kicking in then, by all means, send the owner of the site an angry email.

I have a secret; I delete non-spam comments sometimes! Yes, it’s true! Do you know why? Because this is my website and as such I feel it my responsibility to police the content of it – if a comment is defamatory or just downright rude then I’ll delete it, or if I feel the comment adds absolutely nothing to the post then I’ll delete it. For example, if your comment contains just one word like “Wow!” or “First!” or “Interesting!” then it’ll probably be deleted; why are you wasting your time writing such drivel?

I rarely have a problem though; this is a tiny blog with a tiny readership; something I’ve come to appreciate greatly!

I do feel sorry for the guys at Smashing Magazine! With over 100,000 subscribers they really do get some crap appearing in their comments!

I’m on Github!

Posted in 'General, JavaScript, My Life' by James on May 16th, 2009
I’m on Github!

Yes, finally I’ve joined the masses on Github and I plan to sporadically share special things on there, starting with the following recent developments:

“literalHTML”

A tiny but powerful modification allowing you to specify HTML/DOM structures inline in your JavaScript code, an example:

var className = 'active';
var myMenu = |
    <ul>
        <li class="{className}">Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
    </ul>
|;
 
// myMenu is now a DOM object:
myMenu.nodeName; // "ul"
myMenu.childNodes; // [ <li.active>, <li>, <li> ]
 
// Do something:
jQuery('body').append(myMenu);

View here »

“getDescendants”

Something I required for a project; a function to gather all descendant-elements down until a certain depth is reached:

<div>
    <ul>
        <li>Something <strong>interesting</strong></li>
    </ul>
    <p>Something <span>else</span></p>
</div>

Examples:

var div = document.getElementsByTagName('div')[0];
getDescendants(div, 1); // -> [ <ul>, <p> ]
                        // i.e. children
getDescendants(div, 2); // -> [ <ul>, <p>, <li>, <span> ]
                        // i.e. children + grandchildren
getDescendants(div, 3); // -> [ <ul>, <p>, <li>, <span>, <strong> ]
                        // i.e. children + grandchildren + great-grandchildren

View here »

I’ll hopefully be adding to the repositroy with new exciting discoveries in the near future; visit my profile and “follow me” to stay updated!

Learning jQuery 1.3, the book

Posted in 'General, JavaScript' by James on March 30th, 2009
Learning jQuery 1.3, the book

Not too long ago I acquired a copy of “Learning jQuery 1.3“, a recently released ‘PACKT’ publication written by Karl Swedberg and Jonathan Chaffer. The only books I’ve previously owned relating to web development were not framework/library specific so reading this one was a totally new experience.

The book is mostly aimed at beginners but does cover some more advanced topics so may be of interest to the more savvy web designer or developer. Actually, anyone wanting a solid jQuery reference would benefit from this book!

I’d guess that one of the troubles with writing a book just about a specific topic is that you’re limited to its confines. This book does not start by discussing the DOM API or JavaScript itself, but instead it begins by first explaining the intent of jQuery and then by detailing the jQuery wrapper function and how you can utilise the power of CSS within this magical dollar symbol. jQuery is wonderful but, in my opinion, without a solid foundation in JavaScript you can never be as good as you could be.

The authors did a wonderful job and I don’t think anyone could ask for a better book about jQuery but I cannot help but raise the question of whether or not jQuery is the practical place to start.

I have this image in my head of some hotshot interface designer longing for some hotshot Ajax’y coolness to suit his ego; he wanders into Waterstones and picks up a copy of this jQuery book he’d heard of, he takes it home, and willingly begins on the long journey of learning “jQuery”. If the world were what I wanted, then this guy would soon realise the error of his ways and how he should have learnt JavaScript before venturing into it’s squeeky clean abstractions; but, unfortunately, the world is not like that; the reality is more upsetting – not only will this designer never realise the error of his ways but he’ll live on, writing jQuery everyday, creating bouncy effects and “jQueryfied” web interfaces. Why is that a problem? – Because he will never be able to program in JavaScript he’ll lack the fundamental knowledge that would otherwise ensure him complete cross-browser and timeless sanity!

Dear Apple’s flock…

Posted in 'General' by James on February 17th, 2009
Dear Apple’s flock…

When do you know you’ve gone crazy? – When you’re more impressed by a tool than what you can create with it!

I reckon the great majority of people in this industry would unconditionally subscribe to the conception that an Apple Mac makes you more productive. This little white magical box somehow enhances your ability to produce amazing things, right? Oh and let’s not forget all the other Apple stuff. The iPhone, Ipod, iMac, MacBook, Mac mini – they’re all magical creations tht enhance our existence!

I guess it’s all down to the modern-day infatuation with shiny new technology coupled with manipulative marketeers operating you like a puppet! I mean, seriously, do any of you think that Apple, the corporation, cares a smidge about how productive you are or how innovative your creations are? They don’t! They really don’t give a damn!

Don’t get me wrong, I love new technology – I think it’s great. But I’m not going to consign to this crazed kind of addiction that so many people have. No, I don’t need that new MacBook, I’m perfectly happy with my three year old PC running XP! And speaking of Operating Systems, no! I don’t need Vista, OSX or Windows 7 – I can manage quite happily without all that!

Real web designers use Macs!

Oh I see; all this time I was under the delusion that one’s credibility in this industry was platform agnostic but obviously I’m totally wrong. What was I thinking!? Of course, I see it now, the extent to which a developer is good at his/her job can be solely measured by the software and hardware they use! How could I have ever thought otherwise!?

Grow up! This industry isn’t about my hammer being better than yours; it’s about what I create with my hammer, and what you create with yours! Like the old saying goes "A bad workman blames his tools" – actually, I’d take it further: "A bad workman feels so passionately about his tools that he values them more than his actual work!"

I actually find this quite comical:

There is absolutely no reason in the world you should use anything other than Keynote. Period. I don’t care if you’re on a PC — if you’re serious about speaking, buy a MacBook just for presenting. There is an astounding difference (not an exaggeration) between the tools, canvas placement, typographic control, and overall aesthetics in Keynote compared to PowerPoint. Once you become familiar with Keynote, which isn’t an arduous process, the productivity and just plain enjoyment you’ll experience using it over PowerPoint is completely worth any switching costs.

Obviously Cameron Moll feels that to succeed as a speaker you MUST BUY A MACBOOK!

I’m going to stop now, I feel I may explode!

If you suck at something on a PC you will also suck at it on a Mac!

PS, congratulations Apple, you’ve actually made me want to hold on to my PC out of protest!