Advertisement
Interviews

jQuerified With Karl Swedberg

by

I recently had the extreme pleasure of chatting with Karl Swedberg about Javascript and web development in general. Karl is the author of several Javascript books such as Learning jQuery and jQuery Reference Guide. Join us as we take a look inside the mind of a humble and talented developer.

For those of us who may be unfamiliar with you and your work, tell us more about yourself and what you do for a living

Fusionary

I'm a (mostly front-end) web developer at a small agency, Fusionary Media, in Grand Rapids, Michigan. At 41, I'm probably older than most web developers, but most of the time I still feel like a kid. Outside of work, I'm very involved with jQuery. I'm on the jQuery project team, and I write about it, train others how to use it, and speak about it at conferences.

How and why did you first get involved with web development?

My very first involvement with web development was in 1995, when I built a simple site for a coffeehouse that I owned. After that I dabbled with web stuff here and there, because I really got a kick out of it, but I didn't start doing it as a job until about four years ago.

What are some of your hobbies when you are not working?

I like to read, run, and hang out with my family. Up until a year ago, I had studied karate for about seven years, and I'm considering starting that up again. I also enjoy photography, discovering new music, and geeking out with my friends.

Tell us more about EnglishRules.com and how the website started.

EnglishRules Screenshot

It's a personal blog of mine that I've been neglecting lately. I can't remember exactly when I started it — 2000? 2001? — but the idea was to provide some information and links for my students. I was teaching High School English at the time. Since then it has become a mishmash of my fleeting interests. In 2003 I loaded up Movable Type and started blogging on it. At some point I thought it would be fun to post a a new word each day from whatever I happened to be reading at the time, so I did that for a while. Then I had the crazy notion that I could answer the world's questions about grammar, punctuation, style, spelling, and so on, but that didn't last long. I posted a bunch of my photography on the site for a while, but that has sort of stalled as well. Probably the biggest motivation to keep it running was to give friends and family a snapshot of what I'm doing, but lately Facebook and Twitter have been filling that need.

When did you first become interested in the jQuery javascript library?

I started using jQuery sometime around May or June of 2006. I still have a copy of "Rev 27" of the jQuery core file from May 2, 2006, before it even had a version number. It's a shame the file is compressed and obfuscated. It would be really fun to dig through it and see how much has changed.

Which came first, LearningjQuery.com or the Learning jQuery book?

LearningjQuery Screenshot

The site came first. After playing around with jQuery for a couple months, I thought it would be a good idea to start documenting what I had learned. I asked John Resig if he'd mind my using the jQuery name and blogging about my experiences, and he was enthusiastic about the idea.

A few months after I started the blog, someone from Packt Publishing contacted me and asked if I'd like to write a book about jQuery — an offer that both flattered and terrified me. I agreed to do it, but only if my friend (Jonathan Chaffer) could write it with me. He is a much better programmer than I am, and I was still just a novice at the time.

Why jQuery? Why not MooTools or Prototype?

jQuery Homepage

Choosing a JavaScript library is a lot like choosing a digital SLR camera (once you take price out of the equation, of course). Why Nikon? Why not Canon or Pentax? I'm not sure anyone can satisfactorily answer these questions based on technical merit alone. A lot has to do with intangibles: community, support, compatibility with your already-established mental models about how things should work and look and feel. People also consider extensibility -- in the form of lenses and accessories for cameras and plugins and widgets for JavaScript libraries. Sure, technical merit does play a part. Performance, features, and reliability are important. But as with the camera companies, the JavaScript library developers continue to leapfrog over each other in these areas, and the best one in any one of these areas today may not be the best in that area six months from now.

The reason I chose jQuery in the first place is that it made sense to me almost instantly. I saw that I could easily transfer my knowledge of CSS to jQuery with its DOM-centered approach. Since then, as I've learned more about advanced JavaScript techniques, I have found plain JavaScript sufficient for dealing with the areas of the language that jQuery doesn't address, and haven't felt a need to rely on a library for those areas. I also love the community spirit and the generosity and graciousness of the other members of the project team and the contributors of the discussion lists.

What part of jQuery, or Javascript in general, do you find that new developers struggle with the most?

The question I see asked most often on the jQuery discussion list (Google Group) is along the lines of "Why do my events stop working after I've inserted elements into my document?" We have a detailed FAQ topic that answers this question. I've written a couple articles on learningjquery.com about it. We have the Live Query plugin and, as of jQuery 1.3, the .live() method that solve the problem. Yet despite all of that, the question still comes up a few times a week.

Besides the jQuery docs, where can users find other jQuery resources to help solve any issues they may be having with the library?

jqueryfordesigners Screenshot

Aside from learningjquery.com and the Learning jQuery 1.3 book, there are quite a few great resources. Remy Sharp has some terrific screencasts on his jQuery for Designers, site and I've seen some great articles from Marc Grabanski and James Padolsey on their respective blogs. The jQuery Google Group is very popular, with over 16,000 members and the #jquery IRC channel on freenode.net is quite active and helpful.

Can you name one feature you wish jQuery came packaged with that it currently does not

I wish the .live() method would work with all event types. Currently it only works with a subset, so you can't use it with change, focus, blur, submit, mouseenter, or mouseleave. I also think it would be cool to allow an anonymous function to be used as an argument for .css(), .val(), and .html() the same way it is for .attr().

What tips or advice can you offer those that are relatively new to Javascript? Should they learn Javascript before they move onto jQuery to better understand the subject matter?

I'm afraid these are going to sound like platitudes, but here goes: Don't be afraid to learn as you go. You don't have to have everything figured out ahead of time. Be willing to make mistakes. Keep learning new things about the language, and try to make connections between what you already know and what you're currently learning.

Can you name some 'bad practices' you see being used often with jQuery?

Sure. One bad practice is using jQuery for something that you could do more easily and efficiently with CSS. For example, web developers for years have been changing the background position of an image sprite when the user's mouse hovers over a link. There is absolutely no reason to use jQuery for this, unless the developer wants the hover-state change to be animated.

Another bad practice is unnecessarily repeating selectors. Instead of creating another jQuery object each time you want to do something to a particular set of elements, chain the methods or store a reference to the jQuery object in a variable and use that.

What are some ways one can improve their knowledge of jQuery and become more efficient when working with the framework?

Read tutorials from reputable sites. Ask questions on the discussion list and read answers to other people's questions. In particular, read everything that Michael Geary and Dave Methvin post on the list. Try to emulate the code of great plugin authors such as Mike Alsup, Ariel Flesler, Jörn Zaefferer, and Brandon Aaron.

jQuery plugin development has really taken off over the past two years, do you have any favorite plugins you frequently use or do you prefer to write your own?

jQuery Cycle Plugin

I often write my own, but I do use a few quite frequently. Every client seems to want some kind of image rotator on their homepage, so I use Mike Alsup's Cycle plugin for that. I also use his Form and Media plugins quite a bit. I often rely on Joel Birch's Superfish plugin and Brian Cherne's hoverIntent plugin when a client wants drop-down menus. Lately I've been using jQuery UI more and more for general widget theming, advanced effects, sliders, and draggable/droppable elements.

Are there any specific features (or lack thereof) that you do not like about jQuery?

I'm not crazy about some of the method names in the API. In very early versions of jQuery, there were two method names for traversing all the way up the DOM tree: .parents() and .ancestors(). When the API was trimmed, .ancestors() was dropped. I would have preferred dropping .parents() instead because I think "ancestors" better describes what is being selected. And while in general I like how jQuery overloads methods, I think the .load() and .toggle() methods take the idea a little too far.

You've written numerous books on jQuery, what is the most difficult part of getting these books published?

jQuery Book

The toughest part is probably just staying on schedule. But it's absolutely essential to set a reasonable schedule ahead of time and stick to it the whole way through.

What do you think the future holds for the jQuery framework?

Most of the changes to the jQuery core are going to be in the areas of performance, stability, and bug fixes. I don't see a lot of new features being added to core. For new features, keep an eye on jQuery UI. There is a lot of great new stuff being developed there.

Do you have any more books that you are planning to publish anytime soon?

I'm one of several technical reviewers for a jQuery cookbook that is in the works. But I'm not currently authoring any books and don't have plans to do so any time soon.

Do you have any shameless plugs you would like our readers to know about?

Nothing that hasn't already been mentioned, but thanks for the offer!

Thank you so much for taking the time to chat with me Karl, and thank you for all the great jQuery resources, tricks, and tutorials you have given to the community over the years.

My pleasure! I'm flattered by your interest in what I have to say.


Related Posts
  • Code
    Mobile Development
    In the Spotlight: Brian LeRouxPreview image@2x
    The explosive growth of the mobile space has accelerated the search for a robust and viable cross-platform solution. In 2008, shortly after the introduction of the iPhone SDK and after fiddling with Cocoa and Objective-C, Brian LeRoux and his colleagues at Nitobi decided that their time was better spent building a cross-platform solution than building native mobile applications.Read More…
  • Code
    Plugins
    Choosing the Right Plugin for Your Next WordPress ProjectPlugin icon 400
    Ever needed a plugin for your WordPress-based website? Of course! After all, that's how WordPress is extended, isn't it? If you're a beginner to WordPress, or even a power user, then you're likely familiar with the WordPress plugin repository, premium plugins, and so on. The thing is, there are so many plugins available that do many of the same things, it can be difficult to determine which is best suited for your particular needs. This raises the question: What do you do to find the perfect plugin for a particular need? In this post, we're going to see how to find the best plugin for exactly that.Read More…
  • Code
    Interviews
    Interview With Peter CooperPeter cooper wide retina preview
    Catch up with software developer, Peter Cooper, just in time for O'Reilly's Fluent Conference.Read More…
  • Code
    Interviews
    An Interview with Nick LockwoodNick lockwood profile@2x
    In this interview, I talk to leading iOS developer Nick Lockwood about his open source contributions, his development workflow, and the educational resources he's found useful in mastering the SDK.Read More…
  • Code
    Articles
    What Are You Using? - Nettuts+ Authors EditionCsaba
    I previously asked several top developers the following four simple questions: What's your primary development focus? What hardware are you using for development? Which editor or IDE do you use? What software can you not live without on a daily basis? The article generated a lot of interest and discussion about the tools the community is using which was really great! We love to motivate discussions with our topics. Well, this also motivated us to ask the question, "Why don't we post about what we, the Nettuts+ authors use every day?" So we did just that. We chose ten Nettuts+ authors and asked them the same four questions. And like before, you'll find the answers they gave below and hopefully discover some tools that could make your development much easier. Read More…
  • Code
    JavaScript & AJAX
    Required JavaScript ReadingRequired js retina preview
    I'm asked regularly about books and online resources to get up to speed on JavaScript. Seems like everyone wants to get in on the JS action and with good reason; it's a great language to know if you're interested in exciting career opportunities. It's also pretty fun to play with.Read More…