Live data from Hacker News

You Don't Need JQuery

blog.garstasio.com

191–200 of 201 posts

Re: You Don't Need JQuery

#191

Earlier quoted context omitted.

I definitely don't need you lecturing me about software tools and pretending like I don't question my process. I’m sorry you saw my posts that way. My intent was simply to challenge the specific post to which I responded, where you appeared to be claiming quite clearly but without any particular argument or evidence that projects today should be using Browserify, React and a bunch of NPM modules instead of jQuery. I…

I’m sorry you saw my posts that way. My intent was simply to challenge the specific post to which I responded, where you appeared to be claiming quite clearly but without any particular argument or evidence that projects today should be using Browserify, React and a bunch of NPM modules instead of jQuery. I stand by that challenge and my comments here, but please don’t read more into them than is there. If you don't…

You can chalk all the issues that you've had to growing pains.

No. I’m sorry, but the issues aren’t that simple and you can’t just hand-wave them away like that.

The discovery and maintenance overheads, when libraries get so fine-grained that you wind up spending a lot of time just trying to find decent ones that will be compatible and then keeping an eye on them for updates or replacing them when they are no longer sufficiently supported, can be substantial. This has been an issue with general software development since forever. I sometimes call it the “max problem”: if you need a function to return the maximum of two values and it isn’t part of your language’s standard library, then it is almost certainly going to be faster to implement the one-liner function again on the spot than to search for an existing implementation, but this can easily lead to duplicated code, which is undesirable. The increasing reliance on powerful package managers in front-end web development is just a symptom of these problems.

The downsides of using a framework, meaning code that controls the overall architecture of your system into which you plug your own code as a subservient part, are also real. I’ve written about these on HN before, too[1]. Given that a lot of frameworks implement some sort of plug-in system to try to give back part of the flexibility they inherently take away, it is common to run into the excessive discovery and maintenance overheads I mentioned before on the same projects.

[1] https://news.ycombinator.com/item?id=8070050

In the last 5 years the web browser has changed immensely. It is now capable of running incredibly complex applications.

But they aren’t!

Browsers are now capable of running non-trivial UI applications written in JS, and it’s true that those JS code bases are significantly more complicated than what we worked with a few years ago. However, developers have been building substantial front-end UIs using the likes of Flash or Java to overcome the performance and scalability problems with JS for a long time, and even the largest of these front-ends are only medium-sized projects on the scale of “all software”. There are no magic barriers being discovered in the front-end web development world that haven’t long since been encountered and overcome in other parts of the software industry.

In any case, as I said in my previous post, I am absolutely not suggesting that for these larger JS projects you shouldn’t adopt good tools to automate the development process. Of course you should. I’m just saying that most web sites are nowhere near that scale or complexity, and many don’t need to incur the overheads of adding heavyweight tooling, which is the point I originally objected to. Most sites are not SPAs or CMSes that need to scale up to hundreds or thousands of different types of content.

I think it is also worth keeping in mind that quite a few of the problems these heavy tools solve are only problems in the first place because of other poor tools. As Exhibit A, I cite the use of tools like RequireJS or Browserify to do basic modular design, which is necessary only because JS is a terrible language for developing larger projects and lacks even a basic module system of its own. But again, I’m not disputing that for large web apps by today’s standards a systematic module system is useful, I’m just saying you can go a long way with a one-liner to run Uglify and a one-liner to run SASS, and for many projects that sort of level is all they need.

Using jQuery for building complex interactive web applications is a difficult task because state becomes incredibly hard to reason about.

People keep telling me this, but I have never found it so, and among other things I maintain some substantial code that was built that way and has already successfully outlasted plenty of projects written in trendy web frameworks.

Sure, it’s prohibitively difficult to scale up if you start from the premise that you keep your state embedded in the HTML or the current values of form fields. Toy UIs can get away with this, but it quickly becomes impractical and more structure is needed.

Would I choose to use different tools for a similar project today? Yes, absolutely, there are things we implemented manually a few years ago where it does make sense to use a tried and tested library today.

But there has never been any rule that said you have to rely on bad design and keeping state in odd places, with jQuery or any other library. I was writing web front-end code that did things like separating state from presentation, bundling state changes into a single UI update because rerendering was slow, and implementing what we might now call two-way data binding, long before any of these modern JS frameworks existed. I very much doubt I was the only one. We have a lot of web developers today who have done little if any work on software in other contexts, but these ideas are widespread in other software development contexts and they have been for a very long time.

Likewise, every few years, someone comes along and suggests that a more declarative approach to building UIs is the way forward, and yes, it does have some advantages, but it also has disadvantages. For example, as those using Angular and the like have discovered to their cost, a strategy based on declarative templates doesn’t always scale well when the dominant bottleneck happens when you render changes. This was entirely predictable, I’m afraid, and plenty of people were questioning the Angular hype a year or two back and whether projects locked into using Angular would be difficult to maintain later on. That was before we knew about the whole Angular 2 split, of course.

So, the next logical step is something like React, which is essentially reimplementing a substantial chunk of a web browser on its own terms as an optimisation to overcome the performance limitations of today’s actual web browsers. This is certainly an impressive technical achievement, but will React still be as valuable if a couple of years from now Web Components are ubiquitous and browsers have better logic for avoiding expensive reflows in these kinds of applications? Those both seem like reasonable assumptions, give or take the exact timing.

I urge you to take another look at this stuff. I understand your frustrations but the solution should not be to give up and just go back to jQuery.

As I said before, please don’t read things into my posts that aren’t there. For one thing, I do this for a living, and I keep an eye on this stuff all the time. For another, at no point in this discussion have I suggested that we should just stick with jQuery for everything and not use new tools; in fact, I have explicitly stated otherwise more than once. I challenged one specific post you made, which was a general suggestion that projects should be using tools like Browserify, React and a bunch of NPM-managed modules, even if jQuery was perfectly sufficient to do the necessary job.

Anyway, these posts are getting very long now, and I’ve drifted a long way from my original point so I should probably stop here. Thanks for the discussion.

Re: You Don't Need JQuery

#192

Earlier quoted context omitted.

It's like saying "You don't need a web browser at all -- See how we can navigate the web using cURL!"

Come on. Lynx is the browser.

Nah, I use telnet to browse the Web. No, not using that newfangled Line Mode Browser thingy over at CERN, I mean straight to server port 80.

Re: You Don't Need JQuery

#193

Earlier quoted context omitted.

if it takes 20 seconds to load, you have bigger problems than jquery.

From experience where there is jquery there is normally at least a dozen other js files cut n pasted at random along with a similar number of css files with no thought to efficiency - hell most sites I se they can't even optimised the godamm images using Photoshop properly.

"JQuery is bad because some people who use it do unrelated things wrong"? Should I stop driving because some other people who use cars happen to cheat on their taxes?

Re: You Don't Need JQuery

#194
post #162

An if you care for performance, you shouldn't use jquery. It is very slow: http://stackoverflow.com/questions/11503534/jquery-vs-docume...

But if you care about programmer productivity, you use jQuery, then you profile, then you optimise where required. The last step isn't usually necessary.

I would rather choose something else for productivity.

Re: You Don't Need JQuery

#196

Earlier quoted context omitted.

Not if you're in an environment (like mobile) where you want to reduce repaint.

In which case you don't want to be using jQuery at all and should instead be using a virtual DOM implementation like virtual-dom, famo.us, react or mithril. https://github.com/Matt-Esch/virtual-dom

What if you don't have the option to all of a sudden bust out a new framework? Some of these scenarios are just unrealistic.

Re: You Don't Need JQuery

#198
post #7

You can basically sum up this entire rather ridiculous site with "Yes, you don't need jQuery, you can just use the built-in methods, but using jQuery is generally more pleasant, more consistent, and involves less typing". One particularly egregious example from the site: $('#foo').removeClass('bold'); vs. document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); The au…

Perhaps I'm being a bit dense (I've done prettymuch no front-end JavaScript), but since className gives a single string with class names separated by spaces[1], won't document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); fail if the element in question has more than one class? In that case, you'd need to get the className attribute, split it by spaces, do the repla…

Substitute \bbold\b for ^bold$ -- a potentially introduced extra space in the class name (string) should not matter.

Re: You Don't Need JQuery

#199
A couple days after this was posted to HN, the release of jQuery 1.11.2 and 2.1.3 offers an example of why you might want jQuery even if you might not need it.

http://blog.jquery.com/2014/12/18/jquery-1-11-2-and-2-1-3-re...

> "A bug like this one emphasizes the benefit of using a library like jQuery rather than going directly to the DOM APIs."

Re: You Don't Need JQuery

#200
post #7

You can basically sum up this entire rather ridiculous site with "Yes, you don't need jQuery, you can just use the built-in methods, but using jQuery is generally more pleasant, more consistent, and involves less typing". One particularly egregious example from the site: $('#foo').removeClass('bold'); vs. document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); The au…

I agree that's a lot nicer. But it also looks like essentially a mechanical transformation. Instead of a runtime library (whether jquery or roll-your-own), would it be possible to handle cases like that via syntactic sugar that expands at deployment time, and doesn't require shipping a library to the end-user's browser? (Or does something like that already exist? I haven't really spent any time with CoffeeScript and…

> Instead of a runtime library (whether jquery or roll-your-own), would it be possible to handle cases like that via syntactic sugar that expands at deployment time, and doesn't require shipping a library to the end-user's browser?

You could, but that would require user-agent sniffing (and thus continuous maintenance), and would probably need a pretty unusual caching setup.

Post reply on HN