Adventures in JavaScript Development

Austin

| Comments

In August 2002, it was a little more than a year since I’d left my job at my hometown newspaper. I had just sold my car and left my two jobs as a bartender. Between the tips in my pocket and the money I’d made from selling my car – a 1996 Neon with a probably cracked head gasket – I had about $2,000 to my name. I had a bicycle, camping gear, cooking gear, maps, a handheld GPS, a flip phone, two changes of bicycle clothing, and two changes of street clothes. I was in Camden, Maine, and my parents were taking my picture in front of a bicycle shop.

My destination was Austin. My plan was to ride to Savannah, GA – via Boston, New York, and the eastern shore of Maryland – and then turn right. I didn’t really have much of a plan beyond that, except that I hoped to crash with a friend of a friend when I got to Austin. I heard they had a good bus system. I figured I could sort out a job before my money ran out.

Three weeks and 1,000 miles later, I found myself outside of New Bern, NC, more tan and more fit than I’d ever been or would ever be again. I stopped at a grocery store and picked up food for the evening, tying a bag of apples off the side of my bike. I was planning to camp just south of town, but as I neared a park in the center of town, I found myself surrounded by cyclists setting up camp. They were there for a fund-raising ride, and no, no one would mind if I camped in the park with them instead of riding another 10 miles.

I pitched my tent. I followed them to the free dinner being served for them across the street.

I rode 150 miles – unencumbered by camping gear and all the rest – in the fund-raising ride for the next two days.

I made new friends. They invited me to come stay with them for a few days in Chapel Hill.

I lived with them for a month. I borrowed their 1990 Ford Festiva for a year.

I got a job painting a house. I got a job waitressing. I got a job doing desktop publishing. I got a job making web sites.

I got good at JavaScript. I traveled the world talking about it.

I met a girl. We bought a house. We adopted a baby.

I never made it to Austin, though life has taken me there a few days at a time more times than I can count. Finally, in 2013, I even got a job there. Since February, I’ve made the trek enough times that it’s truly become a home away from home. I’ve stopped using my phone to find my way around. Waitresses recognize me. People tell me about the secret back way to work, but I already know it. I have opinions about breakfast tacos.

It’s time to finish the story I started more than a decade ago, which brings me to the point: With much love for Durham, and for the irreplaceable people who have made our lives so full here, we’re moving to Austin this spring. At last.

Refactoring setInterval-based Polling

| Comments

I came across some code that looked something like this the other day, give or take a few details.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
App.Helpers.checkSyncStatus = function() {
  if (App.get('syncCheck')) { return; }

  var check = function() {
    $.ajax('/sync_status', {
      dataType: 'json',
      success: function(resp) {
        if (resp.status === 'done') {
          App.Helpers.reloadUser(function() {
            clearInterval(App.get('syncCheck'));
            App.set('syncCheck', null);
          });
        }
      }
    });
  };

  App.set('syncCheck', setInterval(check, 1000));
};

The code comes from an app whose server-side code queries a third-party service for new data every now and then. When the server is fetching that new data, certain actions on the front-end are forbidden. The code above was responsible for determining when the server-side sync is complete, and putting the app back in a state where those front-end interactions could be allowed again.

You might have heard that setInterval can be a dangerous thing when it comes to polling a server*, and, looking at the code above, it’s easy to see why. The polling happens every 1000 seconds, whether the request was successful or not. If the request results in an error, or fails, or takes more than 1000 milliseconds, setInterval doesn’t care – it will blindly kick off another request. The interval only gets cleared when the request succeeds and the sync is done.

The first refactoring for this is easy: switch to using setTimeout, and only enqueue another request once we know what happened with the previous one.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
App.Helpers.checkSyncStatus = function() {
  if (App.get('syncCheck')) { return; }

  var check = function() {
    $.ajax('/sync_status', {
      dataType: 'json',
      success: function(resp) {
        if (resp.status === 'done') {
          App.Helpers.reloadUser(function() {
            App.set('syncCheck', null);
          });
        } else {
          setTimeout(check, 1000);
        }
      }
    });
  };

  App.set('syncCheck', true);
};

Now, if the request fails, or takes more than 1000 milliseconds, at least we won’t be perpetrating a mini-DOS attack on our own server.

Our code still has some shortcomings, though. For one thing, we aren’t handling the failure case. Additionally, the rest of our application is stuck looking at the syncCheck property of our App object to figure out when the sync has completed.

We can use a promise to make our function a whole lot more powerful. We’ll return the promise from the function, and also store it as the value of our App object’s syncCheck property. This will let other pieces of code respond to the outcome of the request, whether it succeeds or fails. With a simple guard statement at the beginning of our function, we can also make it so that the checkSyncStatus function will return the promise immediately if a status check is already in progress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
App.Helpers.checkSyncStatus = function() {
  var syncCheck = App.get('syncCheck');
  if (syncCheck) { return syncCheck; }

  var dfd = $.Deferred();
  App.set('syncCheck', dfd.promise());

  var success = function(resp) {
    if (resp.status === 'done') {
      App.Helpers.reloadUser(function() {
        dfd.resolve();
        App.set('syncCheck', null);
      });
    } else {
      setTimeout(check, 1000);
    }
  };

  var fail = function() {
    dfd.reject();
    App.set('syncCheck', null);
  };

  var check = function() {
    var req = $.ajax('/sync_status', { dataType: 'json' });
    req.then( success, fail );
  };

  setTimeout(check, 1000);

  return dfd.promise();
};

Now, we can call our new function, and use the returned promise to react to the eventual outcome of the sync:

1
2
3
4
5
6
7
8
App.Helpers.checkSyncStatus().then(
  // this will run if the sync was successful,
  // once the user has been reloaded
  function() { console.log('it worked'); },

  // this will run if the sync failed
  function() { console.log('it failed'); }
);

With a few more lines of code, we’ve made our function safer – eliminating the possibility of an out-of-control setInterval – and also made it vastly more useful to other pieces of the application that care about the outcome of the sync.

While the example above used jQuery’s promises implementation, there are plenty of other implementations as well, including Sam Breed’s underscore.Deferred, which mimics the behavior of jQuery’s promises without the dependency on jQuery.

* Websockets are a great way to eliminate polling all together, but in the case of this application, they weren’t an option.

Onward

| Comments

My friend IM’d me a link the other day to a document he and a colleague wrote at the end of 2011, listing all the things they wanted to make happen in the world of web development in 2012.

“We did almost all of it,” he said.

“Well shit,” I said. “I should write up something like this for 2013.”

“Why do you think I showed it to you?”


A year ago I was working at Toura, a startup based in New York that was developing software to make it easy to create content-centric mobile applications. I started there as a consultant back in 2010, helping them write a saner version of the prototype they’d developed in the months before.

I got the gig because apparently I spoke with their director of development, Matt, at a meetup in Brooklyn, though I actually have no recollection of this. By this time last year, I’d been there for more than a year, and Matt and I had convinced the company a few months before that the technology we’d developed – a JavaScript framework called Mulberry that ran inside of a Phonegap wrapper – was worth open-sourcing.

I spent much of January and February speaking at meetups and events – Vancouver, Boston, Austin, Charlotte – telling people why Mulberry was something they might consider using to develop their own content-centric mobile apps. By March, though, it was clear that Toura was headed in a direction that was different from where I wanted to go. As it turned out, Matt and I gave our notice on the same day.


April was the first time in almost 10 years that I purposefully didn’t work for a solid month. I spent almost two weeks in Europe, first in Berlin and then in Warsaw for Front Trends. I sold my car – it mostly just sat in the driveway anyway – to make Melissa feel a bit better about the part where I wasn’t making any money. Tiffany was a marvelous host; we took the train together from Berlin to Warsaw for the conference, barely talking the whole way as we worked on our respective presentations. Warsaw was a two-day whirlwind of wonderful people – Melanie, Milos, Chris, Alex, Frances – memorable for my terrible laryngitis and capped by endless hours of post-conference celebration in the hotel lobby, which was magically spotless when we made our way, bleary-eyed, to the train station early the next morning.

I flew home two days later; two days after that, I started at Bocoup.


Taking a job at Bocoup was a strategic change of pace for me. For 18 months, I had been immersed in a single product and a single codebase, and I was the architect of it and the expert on it. As fun as that was, I was ready to broaden my horizons and face a steady stream of new challenges in the company of some extremely bright people.

As it turned out, I ended up focusing a lot more on the training and education side of things at Bocoup – I spent the summer developing an updated and more interactive version of jQuery Fundamentals, and worked through the summer and fall on developing and teaching various JavaScript trainings, including a really fun two-day course on writing testable JavaScript. I also worked on creating a coaching offering, kicked off a screencasts project, and had some great conversations as part of Bocoup on Air. Throughout it all, I kept up a steady schedule of speaking – TXJS, the jQuery Conference, Fronteers, Full Frontal, and more.

Though I was keeping busy and creating lots of new content, there was one thing I wasn’t doing nearly enough of: writing code.


I went to New York in November to speak at the New York Times Open Source Science Fair, and the next day I dropped in on Matt, my old boss from Toura, before heading to the airport. He’s working at another startup these days, and they’re using Ember for their front-end. Though I was lucky enough to get a guided tour of Ember from Tom Dale over the summer, I’d always felt like I wouldn’t really appreciate it until I saw it in use on a sufficiently complex project.

As it turned out, Matt was looking for some JavaScript help; I wasn’t really looking for extra work, but I figured it would be a good chance to dig in to a real Ember project. I told him I’d work for cheap if he’d tolerate me working on nights and weekends. He gave me a feature to work on and access to the repo.

The first few hours with Ember were brutal. The next few hours were manageable. The hours after that were magical. The most exciting part of all, despite all the brain hurting along the way, was that I was solving problems with code again. It felt good.


With much love to my friends and colleagues at Bocoup, I’ve realized it is time to move on. I’ll be taking a few weeks off before starting as a senior software engineer at Bazaarvoice, the company behind the ratings and reviews on the websites of companies such as WalMart, Lowe’s, Costco, Best Buy, and lots more.

If you’re in the JS world, Bazaarvoice might sound familiar because Alex Sexton, of yayQuery, TXJS, and redhead fame, works there. I’ll be joining the team he works on, helping to flesh out, document, test, and implement a JavaScript framework he’s been prototyping for the last several months.

I’ve gotten tiny peeks at the framework as Alex and the rest of the team have been working on it, starting way back in February of last year, when I flew out to Austin, signed an NDA, and spoke at BVJS, an internal conference the company organized to encourage appreciation for JS as a first-class citizen. Talking to Alex and his colleagues over the last few weeks about the work that’s ahead of them, and how I might be able to help, has quite literally given me goosebumps more than once. I can’t wait.


I look back on 2012 with a lot of mixed emotions. I traveled to the UK, to Amsterdam, to Warsaw, to Berlin two times. I broke a bone in a foreign country, achievement unlocked. I learned about hardware and made my first significant code contribution to an open-source project in the process. I met amazing people who inspired me and humbled me, and even made a few new friends.

What I lost sight of, though, was making sure that I was seeking out new challenges and facing them head on, making sure that I was seeking opportunities to learn new things, even when they were hard, even when I didn’t have to. I didn’t realize til my work with Ember just how thoroughly I’d let that slip, and how very much I need it in order to stay sane.

And so while my friend probably has his list of things he will change in the world of web development in 2013, and while maybe I’ll get around to making that list for myself too, the list I want to be sure to look back on, 12 months or so from now, is more personal, and contains one item:

Do work that requires learning new things all the time. Even if that’s a little scary sometimes. Especially if that’s a little scary sometimes. In the end you will be glad.

Two Things About Conditionals in JavaScript

| Comments

Just a quick post, inspired by Laura Kalbag’s post, which included this gem:

We shouldn’t be fearful of writing about what we know. Even if you write from the most basic point of view, about something which has been ‘around for ages’, you’ll likely be saying something new to someone.

One: There is no else if

When you write something like this …

1
2
3
4
5
6
7
function saySomething( msg ) {
  if ( msg === 'Hello' ) {
    console.log('Hello there');
  } else if ( msg === 'Yo' ) {
    console.log('Yo dawg');
  }
}

… then what you’re actually writing is this …

1
2
3
4
5
6
7
8
9
function saySomething( msg ) {
  if ( msg === 'Hello' ) {
    console.log('Hello there');
  } else {
    if ( msg === 'Yo' ) {
      console.log('Yo dawg');
    }
  }
}

That’s because there is no else if in JavaScript. You know how you can write an if statement without any curly braces?

1
if ( foo ) bar() // please don't do this if you want your code to be legible

You’re doing the same thing with the else part of the initial if statement when you write else if: you’re skipping the curly braces for the second if block, the one you’re providing to else. There’s nothing wrong with else if per se, but it’s worth knowing about what’s actually happening.

Two: return Means Never Having to Say else

Consider some code like this:

1
2
3
4
5
6
7
8
9
function howBig( num ) {
  if ( num < 10 ) {
    return 'small';
  } else if ( num >= 10 && num < 100 ) {
    return 'medium';
  } else if ( num >= 100 ) {
    return 'big';
  }
}

If the number we pass to howBig is less than 10, then our function will return 'small'. As soon as it returns, none of the rest of the function will run – this means we can skip the else part entirely, which means our code could look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
function howBig( num ) {
  if ( num < 10 ) {
    return 'small';
  }

  if ( num < 100 ) {
    return 'medium';
  }

  if ( num >= 100 ) {
    return 'big';
  }
}

But wait – if the first if statement isn’t true, and the second if statement isn’t true, then we will always return 'big'. That means the third if statement isn’t even required:

1
2
3
4
5
6
7
8
9
10
11
function howBig( num ) {
  if ( num < 10 ) {
    return 'small';
  }

  if ( num < 100 ) {
    return 'medium';
  }

  return 'big';
}

Note: this post was edited to improve a couple of the examples and to fix some typos.

This Is the Cigarette

This is the cigarette I smoked* on Wednesday after I got out of a meeting in Boston and went to my desk and read my messages and learned that our birthmother “match” had fallen through.

The last three weeks have been among the happiest, most exciting, most terrifying times I can remember. Saying that we are sad and disappointed and et cetera doesn’t really cover it, but, well, there it is. Our search will continue.

* Don’t worry, Mom, I don’t usually smoke. Desperate times, desperate measures.

On Choosing a Syntax Highlighting Scheme for Your Next Presentation

| Comments

This is a projector screen:

You will notice that it is white, or some reasonable approximation thereof. It is probably made of a reflective material that sparkles a bit when light shines on it. Still: white.

Do you know what color this screen is when you use a projector to display this image onto it?

It is still white. Crazy, I know! The thing is, projectors cannot project black; they can only not project any light on a region that you intend to be black.

Chances are you are reading this on an LCD screen of some sort, where the rules are completely different: they usually start out essentially black, not white, and pixels are brightened as required. The pixels that start out dark can generally stay pretty dark.

On a projection screen, on the other hand, the appearance of black is nothing more than an optical illusion, made possible by the projector projecting brightness everywhere else.

What does this mean? Lots of things, but in particular, it means that you should never, ever, ever use a color scheme with a dark background – no matter how high-contrast and good it looks on your monitor – if you will be presenting using a projector that is projecting onto a white screen. At least, assuming that you intend for your audience to be able to actually read the code.

Presentation Color Schemes That I Have Loved

Ben Alman’s TextMate Theme: Ben has tailored this to be incredible for presenting about JS code.

Tomorrow Theme: The light-background flavor is decent, but could probably stand to be higher-contrast, at least for some languages.

Show & Tell

| Comments

I spoke at the Times Open Source Science Fair a couple of weeks ago. I’ll admit that I was pretty skeptical of the concept when I was first asked, but as someone who used to work as an editor at a tiny newspaper in upstate New York, I wasn’t about to say no when the Times asked me to come say hi.

A few days before the event, I got an email asking me for information about what I’d be showing off at my booth. Booth? Wat? They weren’t kidding about the science fair thing, but what the heck was I going to show at a booth?

It turns out this is basically the best idea ever. I recruited my Bocoup colleague Rick Waldron to join me, and together we spent a whirlwind hour showing off robots powered by JavaScript to an endless stream of people walking up to our booth. Rick did a great job of setting up a demo that people could play with, and they took turns moving sliding potentiometers that controlled servos that moved an arm with a gripper at the end, trying to pick up Bocoup stickers. Ours was one of about a dozen booths showing off open-source projects, and the room was a wonderful madhouse.

After a break for dinner, I, Jeremy Ashkenas, and Zach Holman each gave 20-minute talks, but the talks were really just icing on the evening. The “science fair” format promoted such intentional interaction, in a way that traditional conferences just can’t, no matter how great the hall track or the parties may be. The format invited and encouraged attendees to talk to the presenters – indeed, if they didn’t talk to the presenters, there wasn’t much else for them to do. By the time the official talks came around, a super-casual, super-conversational atmosphere had already been established, and the energy that created was tangibly different from any event I’ve been to before.

I love conferences, and the sharing of knowledge that happens there, and there’s a whole lot to be said for their speaker-audience format – don’t get me wrong. But I’d also love to see more events figure out how to integrate this show and tell format. “Booths” don’t need to mean “vendors trying to sell things” – they can actually be a great opportunity to facilitate conversation, and to let open source contributors show off their hard work.

Recent Talks

| Comments

A post from Alex Russell reminded me that I’ve given a number of talks in the last few months, and some of them even have video on the internet.

I’ve been ridiculously spoiled to get to travel all over the place these last few months – San Francisco, New York, Amsterdam, Berlin, Brighton – and speak at some truly first-class conferences, sharing the stage, sharing meals, and sharing beers with some seriously amazing folks. My recent news means I’ll be doing a lot less travel for the next little bit, but I’m ever-so-grateful for the opportunities I’ve had and the people I’ve gotten to see and meet these last few months.

Writing Testable JavaScript

This is the first talk I’ve developed that I’ve managed to give several times in rapid succession: three times in six days, including at Full Frontal, the online JS Summit, and to a group of developers at the New York Times. There’s no video yet, but the slides are here, and there should be video soon, I think.

JS Minty Fresh

A fun talk at Fronteers about eliminating code smells from your JavaScript. The best feedback I got afterwards was from an attendee who said they felt at the beginning of the talk like the material was going to be too basic for them, and by the end of the talk, the material was nearly over their head. “I guess that makes you a good teacher,” he said. Aw!

Rebecca Murphey | JS Minty Fresh: Identifying and Eliminating Smells in Your Code Base | Fronteers 2012 from Fronteers on Vimeo.

Slides

If you like this, you should also check out the screencasts we released at Bocoup earlier this week.

Beyond the DOM: Sane Structure for JS Apps

An update of my code organization talk, delivered at the jQuery Conference in San Francisco. It’s fun for me to see how my thinking around code organization has evolved and improved since my first, now-almost-embarassing talk at the 2009 jQuery Conference in Boston.

Slides

Johnny Five: Bringing the JavaScript Culture to Hardware

This one was from the New York Times Open Source Science Fair, a fun night of about a dozen folks presenting open-source projects at “booths,” followed by short talks about open source by Jeremy Ashkenas, me, and Zach Holman. The slides don’t necessarily stand on their own very well, but the short version is: use JavaScript to make things in the real world, because it’s ridiculously easy and ridiculously fun.

Getting Better at JavaScript

I put this together as a quickie for the Berlin UpFront user group – it was the first talk I gave with my broken foot, and the last talk I’d give for weeks because I lost my voice a couple of hours later. There’s not a whole lot here, but it was a fun talk and a fun group, and a topic that I get plenty of questions about. Again, no video, but here are the slides:

This Is the Cup of Coffee

| Comments

This is the cup of coffee I was making earlier this week when Melissa gave me a thumbs-up while she talked on the phone to a woman in Pennsylvania who had just finished telling Melissa that yes, indeed, after 10 weeks or three years of waiting depending on how you count, a 29-year-old woman who’s due to give birth in Iowa at the beginning of February has decided that Melissa and I should be so lucky as to get to be her baby girl’s forever family.

Most people get to post ultrasound pictures on Twitter at moments like these, but for now this will suffice to remind me of the moment I found out I would get to be a mom. My head is spinning, and while on the one hand it’s a little difficult to fathom that this is all just 10 weeks away, on the other hand I’m counting down the days.

Our adoption will be an open one; the meaning of “open” varies widely, but in our case it means we talked to the birth mother before she chose us, we’ll be meeting her in a few weeks, we’ll do our very best to be in Iowa for the delivery, and we’ll stay in touch with letters and pictures afterwards. Melissa and I are grateful that we’ll be able to adopt as a couple, though we are saddened that we have to adopt outside of our home state of North Carolina in order to do so. It’s important to us that our child have both of us as her legal parents, and I don’t hesitate to say that it’s downright shitty that we have to jump through significant legal and financial hoops – and stay in a hotel in Iowa with a newborn for an unknown number of days – to make it so. It is what it is, and good people are working and voting to make it better, and it can’t happen fast enough.

I’ve learned a lot about adoption these past few months, and I know a lot of people have a lot of questions, some of which they’re reluctant to ask. If you’re interested in learning more, I highly recommend In On It: What Adoptive Parents Would Like You to Know About Adoption. You’re also welcome to ask me questions if you see me in real life or on the internets – I can’t promise I’ll know the answers, but I promise to do my best.

In the meantime, wish us luck :)

A Baseline for Front-End Developers

| Comments

I wrote a README the other day for a project that I’m hoping other developers will look at and learn from, and as I was writing it, I realized that it was the sort of thing that might have intimidated the hell out of me a couple of years ago, what with its casual mentions of Node, npm, Homebrew, git, tests, and development and production builds.

Once upon a time, editing files, testing them locally (as best as we could, anyway), and then FTPing them to the server was the essential workflow of a front-end dev. We measured our mettle based on our ability to wrangle IE6 into submission or achieve pixel perfection across browsers. Many members of the community – myself included – lacked traditional programming experience. HTML, CSS, and JavaScript – usually in the form of jQuery – were self-taught skills.

Something has changed in the last couple of years. Maybe it’s the result of people starting to take front-end dev seriously, maybe it’s browser vendors mostly getting their shit together, or maybe it’s front-end devs – again, myself included – coming to see some well-established light about the process of software development.

Whatever it is, I think we’re seeing the emphasis shift from valuing trivia to valuing tools. There’s a new set of baseline skills required in order to be successful as a front-end developer, and developers who don’t meet this baseline are going to start feeling more and more left behind as those who are sharing their knowledge start to assume that certain things go without saying.

Here are a few things that I want to start expecting people to be familiar with, along with some resources you can use if you feel like you need to get up to speed. (Thanks to Paul Irish, Mike Taylor, Angus Croll, and Vlad Filippov for their contributions.)

JavaScript

This might go without saying, but simply knowing a JavaScript library isn’t sufficient any more. I’m not saying you need to know how to implement all the features of a library in plain JavaScript, but you should know when a library is actually required, and be capable of working with plain old JavaScript when it’s not.

That means that you’ve read JavaScript: The Good Parts – hopefully more than once. You understand data structures like objects and arrays; functions, including how and why you would call and apply them; working with prototypal inheritance; and managing the asynchronicity of it all.

If your plain JS fu is weak, here are some resources to help you out:

Git (and a Github account)

If you’re not on Github, you’re essentially unable to participate in the rich open-source community that has arisen around front-end development technologies. Cloning a repo to try it out should be second-nature to you, and you should understand how to use branches on collaborative projects.

Need to boost your git skills?

Modularity, dependency management, and production builds

The days of managing dependencies by throwing one more script or style tag on the page are long gone. Even if you haven’t been able to incorporate great tools like RequireJS into your workflow at work, you should find time to investigate them in a personal project or in a project like Backbone Boilerplate, because the benefits they convey are huge. RequireJS in particular lets you develop with small, modular JS and CSS files, and then concatenates and minifies them via its optimization tool for production use.

Skeptical of AMD? That’s no excuse to be doing nothing. At the very least, you should be aware of tools like UglifyJS or Closure Compiler that will intelligently minify your code, and then concatenate those minified files prior to production.

If you’re writing plain CSS – that is, if you’re not using a preprocessor like Sass or Stylus – RequireJS can help you keep your CSS files modular, too. Use @import statements in a base file to load dependencies for development, and then run the RequireJS optimizer on the base file to create a file built for production.

In-Browser Developer Tools

Browser-based development tools have improved tremendously over the last couple of years, and they can dramatically improve your development experience if you know how to use them. (Hint: if you’re still using alert to debug your code, you’re wasting a lot of time.)

You should probably find one browser whose developer tools you primarily use – I’m partial to Google Chrome’s Developer Tools these days – but don’t dismiss the tools in other browsers out of hand, because they are constantly adding useful features based on developer feedback. Opera’s Dragonfly in particular has some features that make its developer tools stand out, such as an (experimental) CSS profiler, customizable keyboard shortcuts, remote debugging without requiring a USB connection, and the ability to save and use custom color palettes.

If your understanding of browser dev tools is limited, Fixing these jQuery is a great (and not particularly jQuery-centric) overview of debugging, including how to do step debugging – a life-altering thing to learn if you don’t already know it.

The command line

Speaking of the command line, being comfortable with it is no longer optional – you’re missing out on way too much if you’re not ready to head over to a terminal window and get your hands dirty. I’m not saying you have to do everything in the terminal – I won’t take your git GUI away from you even though I think you’ll be better off without it eventually – but you should absolutely have a terminal window open for whatever project you’re working on. There are a few command line tasks you should be able to do without thinking:

  • ssh to log in to another machine or server
  • scp to copy files to another machine or server
  • ack or grep to find files in a project that contain a string or pattern
  • find to locate files whose names match a given pattern
  • git to do at least basic things like add, commit, status, and pull
  • brew to use Homebrew to install packages
  • npm to install Node packages
  • gem to install Ruby packages

If there are commands you use frequently, edit your .bashrc or .profile or .zshrc or whatever, and create an alias so you don’t have to type as much. You can also add aliases to your ~/.gitconfig file. Gianni Chiappetta’s dotfiles are an excellent inspiration for what’s possible.

Note: If you’re on Windows, I don’t begin to know how to help you, aside from suggesting Cygwin. Right or wrong, participating in the open-source front-end developer community is materially more difficult on a Windows machine. On the bright side, MacBook Airs are cheap, powerful, and ridiculously portable, and there’s always Ubuntu or another *nix.

Client-side templating

It wasn’t so long ago that it was entirely typical for servers to respond to XHRs with a snippet of HTML, but sometime in the last 12 to 18 months, the front-end dev community saw the light and started demanding pure data from the server instead. Turning that data into HTML ready to be inserted in the DOM can be a messy and unmaintainable process if it’s done directly in your code. That’s where client-side templating libraries come in: they let you maintain templates that, when mixed with some data, turn into a string of HTML. Need help picking a templating tool? Garann Means’ template chooser can point you in the right direction.

CSS preprocessors

Paul Irish noted the other day that we’re starting to see front-end devs write code that’s very different from what ends up in production, and code written with CSS preprocessors is a shining example of this. There’s still a vocal crowd that feels that pure CSS is the only way to go, but they’re starting to come around. These tools give you features that arguably should be in CSS proper by now – variables, math, logic, mixins – and they can also help smooth over the CSS property prefix mess.

Testing

One of the joys of writing modular, loosely coupled code is that your code becomes vastly easier to test, and with tools like Grunt, setting up a project to include tests has never been easier. Grunt comes with QUnit integration, but there are a host of testing frameworks that you can choose from – Jasmine and Mocha are a couple of my current favorites – depending on your preferred style and the makeup of the rest of your stack.

While testing is a joy when your code is modular and loosely coupled, testing code that’s not well organized can be somewhere between difficult and impossible. On the other hand, forcing yourself to write tests – perhaps before you even write the code – will help you organize your thinking and your code. It will also let you refactor your code with greater confidence down the line.

  • A short screencast I recorded about testing your jQuery with Jasmine.
  • An example of unit tests on the jquery-bbq plugin.

Process automation (rake/make/grunt/etc.)

Grunt’s ability to set up a project with built-in support for unit tests is one example of process automation. The reality of front-end development is that there’s a whole lot of repetitive stuff we have to do, but as a friend once told me, a good developer is a lazy developer: as a rule of thumb, if you find yourself doing the same thing three times, it’s time to automate it.

Tools like make have been around for a long time to help us with this, but there’s also rake, grunt, and others. Learning a language other than JavaScript can be extremely helpful if you want to automate tasks that deal with the filesystem, as Node’s async nature can become a real burden when you’re just manipulating files. There are lots of task-specific automation tools, too – tools for deployment, build generation, code quality assurance, and more.

Code quality

If you’ve ever been bitten by a missing semicolon or an extra comma, you know how much time can be lost to subtle flaws in your code. That’s why you’re running your code through a tool like JSHint, right? It’s configurable and has lots of ways to integrate it into your editor or build process.

The fine manual

Alas, there is no manual for front-end development, but MDN comes pretty close. Good front-end devs know to prefix any search engine query with mdn – for example, mdn javascript arrays – in order to avoid the for-profit plague that is w3schools.

The End

As with anything, reading about these things won’t make you an expert, or even moderately skilled – the only surefire way to get better at a thing is to do that thing. Good luck.