The article is not complaining about jQuery. A "code smell" is something in the code that is not necessarily bad in itself, but may indicate that the code's author is inexperienced or unskilled. Such code may contain subtler errors.
The author is pointing out coding practices that cause him to suspect that others' jQuery code may not be very good.
You've misunderstood the intent of the post. It's mostly my fault -- I shouldn't have named it "jQuery code smells". The point of the post was to list jQuery code snippets that exhibit "code smells", -- you seem to be under the impression that I think that jQuery itself, smells. And that couldn't be further from the truth.
Re:JQuery Code Smells
by RyanMcGreal on Thursday January 07, 2010 @01:59PM
(#1037744)
> you seem to be under the impression that I think that jQuery itself, smells.
That's exactly what I thought ... until I read the article. Your intent seems pretty clear to me; but if a lot of people are misunderstanding you, that's a good sign you need to change the message to address the widespread confusion.
Re:JQuery Code Smells
by IgorPartola on Thursday January 07, 2010 @01:21PM
(#1037639)
Actually, I was under the impression that you were putting the blame for sub-par code on jQuery, not on the people using it. I agree that most of these practices a at least a bit odd, but thankfully jQuery does not force any of them upon you.
Simple editorial fix: Add quotes to the title to clarify that you're referring to the noun, "jQuery 'Code Smells'", rather than making the statement that "jQuery Code is Smelly".
Agreed with regard to the HTML point. There are a bunch of things that can be done with string concatenation that can improve performance significantly. It may not be pretty to have HTML strings embedded in the JavaScript, but sometimes it is necessary to achieve acceptable performance.
So don't do it. It's not required.
> Concatenating a bunch of things together to make a selector
This is semi-valid and using the jQuery.filter() function helps a bit. Overall though, it's not a huge problem, IMHO. Just put together the selector incrementally. Likely you need bits of that selector elsewhere anyways.
> Going over the top with chaining
I've written some complex code using jQuery and none of it had a chain as long as your example. Still don't see how this is jQuery's fault.
> Not caching collections
Then cache them. How is jQuery preventing you from doing this?
> HTML
This is just runs faster. When performance is critical, I find it acceptable to do this.