jQuery is for n00bs

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 guy, 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.

Follow me on Twitter

Creating a Rails 3 application from a source install

I decided to make a quick post about creating a Rails 3 app from a source install of Rails because setup in Edge Rails changes so often and the documentation is usually outdated.

So here you go:

Clone the rails repo from github

bob@guinness ~/projects  $ git clone http://github.com/rails/rails.git
Initialized empty Git repository in /Users/bob/projects/rails/.git/
got 78fffac66895b0239b83138d19ae09b32718cb5b
walk 78fffac66895b0239b83138d19ae09b32718cb5b
...
cd rails   # Don't forget this or you will be in the wrong directory for the rest of the tutorial

Only do this if you have a an old version of bundler

bob@guinness ~/projects/rails $ rm -rf ~/.bundle/ ~/.gem/ .bundle/ Gemfile.lock

My version of rubygems was old and didn’t support the new bundler version

bob@guinness ~/projects/rails $ sudo gem update --system --no-ri --no-rdoc
Updating RubyGems
Nothing to update

Get the updated bundler

bob@guinness ~/projects/rails $ sudo gem install bundler --no-ri --no-rdoc
Successfully installed bundler-0.9.25
1 gem installed

You’ll need thor

bob@guinness ~/projects  $ sudo gem install thor --no-rdoc --no-ri
Successfully installed thor-0.13.6
1 gem installed

Bundle the rails dependencies

bob@guinness ~/projects/rails $ bundle install
Fetching git://github.com/rails/arel.git
Fetching source index from http://rubygems.org/
Updating git://github.com/rails/arel.git
Using rake (0.8.7) from system gems
Installing RedCloth (4.2.3) from rubygems repository at http://rubygems.org/ with native extensions
Using abstract (1.0.0) from system gems
Using builder (2.1.2) from system gems
Installing i18n (0.4.0.beta1) from rubygems repository at http://rubygems.org/
# There will be quite a few dependencies installed by bundler
...
Installing yajl-ruby (0.7.6) from rubygems repository at http://rubygems.org/ with native extensions Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Make sure it all worked out :)

bob@guinness ~/projects/rails $ bundle show arel
/Users/bob/.bundle/ruby/1.8/bundler/gems/arel-8151ac946644aab31601d7c0ed944eb9d7ea1e6b-master

Create your rails app

bob@guinness ~/projects/rails $ ruby bin/rails ../rails3app --dev
create
create  README
create  Rakefile
create  config.ru
create  .gitignore
create  Gemfile
create  app
create  app/controllers/application_controller.rb
create  app/helpers/application_helper.rb
... # This is standard rails 3 application scaffolding
create  vendor/plugins/.gitkeep
run  bundle install from "."

Start your rails 3 app

bob@guinness ~/projects/rails $ cd ../rails3app
bob@guinness ~/projects/rails3app  $ script/rails server
=> Booting WEBrick
=> Rails 3.0.0.beta3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-05-24 22:41:47] INFO  WEBrick 1.3.1
[2010-05-24 22:41:47] INFO  ruby 1.8.7 (2009-06-12) [i686-darwin10]
[2010-05-24 22:41:47] INFO  WEBrick::HTTPServer#start: pid=38457 port=3000

Point your browser at http://localhost:3000.

BAM! You are running your Rails 3 app from a source install.

Introducing Kumite

KumiteInspired by something that I was working on at Grockit and in an attempt to possibly make some money, I decided to start working on a new realtime whiteboarding app called Kumite. You can check out the demo at kumite.bobremeika.com. It’s very rough, I basically hacked it together this weekend, but I will be fixing bugs and implementing new features as quickly as I can.

Go ahead and try it out! I will be adding a more detailed post soon.

Starting a new opportunity at Yammer!

I recently left Grockit, Inc. to start a new opportunity at Yammer. Before I get too far into my excitement for Yammer, I need to give credit where credit is due.

Grockit is excellent place to work, and I tremendously enjoyed the year and a half that I spent there. Grockit has a great staff and fosters a creative environment where code cleanliness matters *a lot*. In general, I find that clean code is extremely important for maintaining programmer happiness and anybody looking for a job should strongly consider what the code base probably looks like before considering new employment. Of course any code base that requires any kind of algorithmic complexity, stringent performance requirements or changing business logic is bound to have a few warts, but Grockit does a pretty good job at minimizing these problems. In general, the code is pretty clean specifically when compared to other companies where I’ve worked that build hacks on top of hacks in order to hit some impossible deadlines.

Grockit also has a very smooth project planning-prototype-production development pipeline. Deadlines are rare and while this may seem counter intuitive to engineers or project managers coming from more traditional backgrounds, it actually works very well. In my time at Grockit, we generally knew exactly what needed to be done and we would hit important development milestones at blazing speeds while still finding time for important code refactoring and performance enhancements.

Jan is a Maverick

Oh… and did I mention that the people are smart? Try really smart. If degrees from prestigious colleges is what you use as a barometer for baseline intelligence then Grockit has got you covered. Grads from MIT and Harvard walk the halls munching on free food from the gourmet chef.

So anyway… Grockit is a great place to work and the decision to leave was emotional. I have no doubt that they will be successful. CEO Farb Nivi recently secured more funding which I know will be used to achieve his goal for a “benevolent takeover” of the education industry. Good luck to all of the friends that I made there… we won’t be strangers.

That being said, I am extremely thrilled to start at Yammer! Working at Grockit gives you, as a developer, a unique privilege to be highly selective when moving to a new company. Of the many companies that I talked to (the job market is hot right now), Yammer was the most compelling from a business model standpoint and a technology standpoint. When I met with CTO Adam Pisoni and CEO David Sacks, I was instantly impressed with their understanding of their business space and their knack for finding new opportunities in that space. Adam also described some of their upcoming features and some general technical approaches to implementing those features.

A couple of open source projects that I contribute to in my free time are being used in their technology stack so Yammer instantly hit a few sweet spots for me… e.g. I already work on a lot of this stuff for free and now I get to be paid for it (awesome!). Yammer also has free food and beer (more awesome!).

The people I met with during the interview process at Yammer impressed me with their technical knowledge as well as their character. When I asked a few probing questions about their code base I was happy to hear the answers that I received. It’s always nice when you have an opportunity to learn from a large code base, and I think I will get that opportunity from Yammer. I’m also looking forward to solving a whole set of unique problems that I haven’t been exposed to in the past.

So… my first day at Yammer will be next Tuesday. I can’t wait to get into the code and see how things work over there. It’s going to be exciting!

UPDATE 15:32: Fixed some grammatical errors.

Creating a cometd server in code

I’m not a huge java guy, but I dabble.

When I need to create a new cometd project from scratch, which isn’t often, I always have a problem with using XML files to configure my web app. Maybe it’s because I am just used to writing code to do these things and I feel more comfortable with that process, or maybe it’s because my ruby background makes me despise the java stack for it’s endless configuration bullshit.

Either way, I’m posting this for my own reference and maybe this will wind up helping somebody else out.

Here is how you create a cometd application from your main method under the Java Servlets 3.0 and cometd-java 2.0:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class App
{
    public static void main( String[] args )
    {
      Server server = new Server(8080);
      ServletContextHandler context = new ServletContextHandler();
      ServletHolder servletHolder = new ServletHolder(CometdServlet.class);
      context.setContextPath("/");
      context.addServlet(servletHolder, "/cometd/*");

      try {
        server.start();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
}

Now if you point a comet clients at http://somehost:8080/cometd you will start to see some hot real-time client-on-client action.