By July 14, 2010

Late to the JQuery Party

You may be wondering what happened to my usual Monday post.

Well, I was having my head rearranged by JQuery.  I have to admit, I am pretty late to the party.  I haven’t really been using JQuery at all the past few years.

I missed a lot.


Goodbye type safety

This part scares me a little bit.  I already made a few typos that were pretty hard to detect.

Debugging javascript is not much fun considering that data and methods are both first class citizens.

But, the trade-off just might be worth it.

What we are losing in type safety, we are making up for in productivity and speed.  It is really fast to manipulate a page using JQuery and to hook up events.

I still wish there was some way to have some sort of type safety when using JQuery or Javascript in general, but it really hurts my brain to try and think about how that would be possible.

Perhaps some kind of Script# / JQuery bastard child?

I know some people are doing Javascript unit testing.  That would certainly make me feel safer not having type safety.

Functional thinking

I like the functional thinking paradigm.  One of my co-workers was saying that he likes JQuery because it helps him to write Lamba expressions and LINQ queries.  I tend to agree with him.

I’ve said it before, but I believe the next high abstraction of programming is thinking functionally.

So many pieces of code that I would have used code generation to produce in the past, I can now produce with Lambda expressions.

It’s not all roses

I do have some major issues with JQuery and Javascript in general.  One of the big problems is that JQuery is not a language, and it’s not a library.  It is a DSL built on top of a language.

Bleeding all the way through the stack

The downfall of this is that it is a very leaky abstraction.  Abstractions are good because they allow us to think at a higher level.

Leaky abstractions are bad because they force us to context switch from a higher level of thinking down to a lower level.

In order to understand JQuery you must understand Javascript, the DOM and CSS to some extent.

Think for a second about all the “languages” or technologies you have to know to develop an ASP.NET web page using JQuery and MVC.

  • HTML
  • C# or Visual Basic
  • JSON
  • Javascript
  • JQuery
  • CSS
  • Web Services / Rest
  • HTTP (You need to be able to debug all the coolness you are flinging back and forth.)

When you have it all working, it is pretty slick.  Very slick indeed, but it is not a sustainable model.  It is complex and sprinkled with errors and gotchas.

Debugging / readability

When I am writing JQuery, although I feel like it is magical and cool, I also feel a little bit dirty.


Well, as clean as you try to write JQuery code, it can be pretty nasty.  There is a lot of magic going on and it is not very easily understandable.

Perhaps I’ll get better at expressing my intent clearly in JQuery code, but I am pretty sure it has to due in part with the leakiness of the abstraction layer, and that can’t really be cleaned up easily.

Debugging is also hell.  I tried debugging through the validation library to see why my error messages weren’t showing up, and it was no picnic.

Javascript itself is notoriously difficult to debug because objects can have methods dynamically added to them and all the other little tricks make it hard to look at a watch window and get anything useful out of an object.

View logic

One of the things I really enjoyed while writing JQuery code was putting the view logic where it really belongs.  It is nice to have a language and a server separating the view logic from the model and presentation.

JQuery really allows you to put all the code that manipulates the view in one place, and on the client side, where it really belongs.

JQuery will make your HTML code so much cleaner and helps to actually plug the leaks in the HTML abstraction layer.  (Although it isn’t perfect, especially when working with ASP.NET Web Forms.)

Better late then never at all

So I know I’m really late to the JQuery party, but I’m here now and I am liking it.

Overall, I’d recommend taking a look at JQuery if you are like me and hadn’t really used it until now.  It definitely is a valuable skill to develop and is growing at an extremely rapid pace.

About the author

John Sonmez

John Sonmez is the founder of Simple Programmer and a life coach for software developers. He is the best selling author of the book "Soft Skills: The Software Developer's Life Manual."