Hacker News new | ask | show | jobs
by kaoD 3131 days ago
Don't. Please. I don't want to maintain your state spaghetti.

Or if you don't have state to manage, but a few small interactions, just use the plain browser API.

Back in the day jQuery was useful to maintain developer sanity across all the different browser API implementations and their quirks but, nowadays, it's mostly an unnecessary dependency. Even AJAX, which jQuery simplified immensely, has been superseded by fetch.

90% of jQuery code out there is querySelectorAll and fetch.

2 comments

Not all frontend code needs state management in fact most could benefit feom having he state managed externally = websockets.

Plain javascript is ideal. If for semi-unsimple form validation you need to reach for a full featured framework and create a reusable component that will only be used once, stop. jQuery can simplify the experience.

I didn't make it clear: I meant UI state, not application state. DOM manipulation is inherently stateful, and there is no way websockets are going to help with it.

Now your state can live in up to three places: DOM, JS and backend. It's even easier to desync UI state unless you rebuild the page from scratch (sending complete HTML as in old-school AJAX... or using React and the likes to make it fast enough to apply a diff of DOM changes).

I agree you don't need a framework for simple frontend code like form validation but:

> jQuery can simplify the experience.

How so? I'll quote my other reply:

> jQuery brings nothing to the table in 2017. I'm willing to be proved wrong. Is there anything that jQuery vastly simplifies?

(Compared to vanilla JS + CSS)

> Don't. Please. I don't want to maintain your state spaghetti.

I fail to understand how not using jQuery prevents anyone from writing spaghetti code.

I've seen plenty of spaghetti code written with "framework du jour", Angular and React included.

> state spaghetti

State is particularly hard to manage using jQuery because, unlike frameworks, it has no builtin way to deal with it.

The disconnect between DOM and JS state is what makes frontend programming a pain to deal with. This led to ad-hoc bug-ridden "state machines" (i.e. spaghetti global variables all over the place) that broke at the very first unexpected interaction.

If you're using a proper state machine (or your program is simple enough to not need them) you're better off just using the regular browser API.

jQuery brings nothing to the table in 2017. I'm willing to be proved wrong. Is there anything that jQuery vastly simplifies?