jQuery is for n00bs

Posted on March 3, 2011, 10:23 am, by Bob Remeika, under Uncategorized.

So the CEO comes to you and is all like “I wanna build the next Facebook killer”, and your all like “Fuck ya! I’ve been waiting for this chance ever since I learned PHP!”. So forget the massive backend infrastructure and that you didn’t even know what graph theory was until they hired that PHD who kept talking about O-n-squared like it’s a bad thing. Your job is to build the front end.

So how do you do it?

Well John Resig and Doug Crockford are your Jesuses (or Jesusi? How do you pluralize Jesus… the guy is a fucking God), so you’re all like, “Well jQuery worked on awesomepetsbyphilandphillis.com… so $(function(){}) this bitch”. So you start coding like a bat out of hell. Before you know it, you’ve got a login form and a dialog box and shit is all peaches and cream. You are a God! All you had to do was grab a plugin here and there… you didn’t have to do shit! And then BLAM! BETA!!! Valleywag is now following your CEO on Twitter and Michael Arrington is pleading with you to enter the Techcrunch 50. You are going to be RICH!

So now you’re feeling pretty good about yourself and that PHD is thinking, why the fuck did I spend $150K on college when I could have just read “Javascript the Good Parts” and been the next internet hero? Not so fast sparky.

The Rails Developer

You’re a startup so you are inevitably going to be a Rails shop and you will hire a “Ruby Rockstar”. Don’t argue with me on this.

So like I was saying… you hire this “Rock Star” and then all of a sudden he’s dissin’ your shit. “What the fuck is this inline Javascript?” and your response is “Dude, I’m gonna clean it up, we’re a startup YAGNI… Agile… cough cough”. So you start cleaning up your Javascript and then you realize “Oh, there’s some common patterns here”. So you start making some classes, cause that’s what Doug said to do. Then you’re like, “Wait, Javascript doesn’t have classes” (or inheritance…. at least not the kind you read about in Learn Java in 21 days), but dude it’s cool. Class.js

So you add class.js into your growing number of dependencies and off you go again. You have classes now and life is starting to make sense, but your app continues to grow, and all of that shit that was starting to make sense is now falling apart. jQuery UI will get you an awesome fucking date picker but the CEO is talking about going international and adding some consistency to the user experience. You want to be everywhere… mobile, desktop, web and beyoooooooooooooooond! The CTO is annoyed about the lack of keyboard controls in the FriendPicker plugin you wrote, but that’ll take a week… and then another week. “She just doesn’t have the power, Captain” you say, but if you don’t get the fuck out of this Romulan tractor beam then you’re fucked. Wait… whaaaaa?

So now what?

Your job was to build a full fledged app, but there’s no way you could have seen this massive shitpile of shit coming down the ephemeral pike (is it pike or pipe? People disagree). Your solution is to build a widget rendering system, some core Javascript utilities, some abstactions upon abstractions (he said mobile didn’t he?). All of a sudden you have a directory tree that looks like this:

public/javascripts/app — Rails BRTCHES!

- application.js — Rails BRTCHES!

- prototype.js — Rails BRTCHES!

- core.js

- core.seriously.js

- util.js

- jquery.1.4.2.js

- underscore.js

- mobile.bitch\!.js

- plugins/

- lightbox-0.5.2.js

- thickbox.js — Cause lightbox didn’t do everything

- gallery-1.1.1.js

- rating-1.23.4.js

- carousel-1.23324234354354353453453453.23.js

… eight hundred or more non-interconnected files

- widgets/

- base.js

- FriendPicker.js

- NosePicker.js

… blah blah blah.. who cares.

What’s missing?

Aside from the fact that you now have dependency galore and that your rating plugin requires underscore 1.0.4, but your awesome gallery plugin requires underscore 0.6.0, you have no fucking tests. Every time you deploy to production your CEO finds out that NosePicker throws an error when he actually picks his nose and eats it, but not when he just picks and flicks.

Your godly status is now tarnished, that PHD is feeling pretty good about his $150K investment, and the Rock Star thinks you’re a douche.

You should have used Dojo you fucking n00b

I’m sorry if I hurt your n00b feelings but because jQuery is so ubiquitous now, I feel like this needs to be said. Remember what Rails did for Ruby? It made it you so you didn’t have to think about your directory tree layout and you didn’t have to nerd fight about what was business logic and what was display logic. You didn’t even know that tracking your database changes should go in source control, but Rails taught you that. You never thought about writing clean, readable, testable code because you were the only one touching it. Rails started doing this for you about 5 or 6 years ago and you didn’t fucking appreciate it. Maybe you didn’t learn it because you cringed at the thought of agreeing with a loudmouth Dutch asshole, or maybe you were just trying to get shit done. I don’t care. Rails brought a lot of design patterns and good coding practices into the webdev world and you should at least look at rails because it will make you a better programmer.

Dojo does this

Dojo does this for you too (and it’s been doing so since before Rails was a gleam in DHH’s eye), and honestly, go ahead and use jQuery. Dojo sucks at marketing whereas jQuery kicks total ass, but when you invent your brand new shitty jQuery plugin don’t post it on your blog like you invented something new. Dojo has a full-fledge i18n widget system complete with keyboard controls theming and a11y. It has a ton of core widgets that you need all of the time and it has a framework for creating custom widgets when you wanna do something crazy. Your whole UI lifecycle is taken care of for you and you don’t have to think about it or debate it with the new Javascript Guy. You don’t have to worry about dependencies because Dojo has everything you need to build that next great Facebook Killer.

But the Learning Curve for Dojo is too High

So is learning curve for building a stable performant RIA (is that term passe?). jQuery gives you an awesome API for querying the DOM (thanks John for “Thinking Different”) and providing cross platform consistency, but it does nothing for you when you want to build some bad ass computer shit or maybe just a thick client. You have to do that yourself. I’m not saying its impossible n00berson, I’m just saying it’s hard. Now I will give you the fact that the docs just “aren’t quite there” (hint: they never will be) or that when you download the source bundle it’s extremely terrifying at first glance. But I guarantee you that you won’t you won’t see the Dojo community oohing and ahhing over something simple.

Fine, Use jQuery, but You Will Need Dojo

I understand that 90% of people just want to add a single lightbox or add a drop-down menu to their navigation. I’m not saying that Dojo is for everything. jQuery and it’s plethora of plugins and community support will handle the simple shit for you. I’m talking to all of the n00bs out there that think they are going to get away with writing 5000 LOC and don’t realize that it will become a mess. You people… YOU! are the ones that need Dojo. You need guidance, because nobody has ever written the app that you’re writing. You’re unique, just like you kindergarten teacher told you. I’m just saying that maybe you can learn something from people that have built some crazy shit.

Before you reinvent the wheel… give Dojo a look… because Dojo already did that. TM

Full disclosure… I sat on this blog entry for months before I posted it.