diegof79
3 months ago
I worked with Backbone, Angular 1, Ember, and then React.
The article overlooks the problems that made React popular:
- Composition: Composing components is easier and more efficient in React. Backbone’s render function assumes "this.$el" is mounted and available in the DOM. That makes composition difficult: you cannot simply nest one component inside another without managing the DOM lifecycle of subcomponents. You don’t need 1.000 components to feel the pain.
- Event handling: You can’t pass an event handler as a string, so the events object must be paired with the selector to locate the element. Any structural changes require updating selectors or managing unique IDs.
- State management: Re-rendering components when state changes becomes messy in Backbone fairly quickly. That mess is why Angular 1 gained popularity. React simplifies this further by enforcing a one-directional state flow.
- Efficient DOM updates: Even if you implement composition and state management ad hoc, you still must update the DOM efficiently to avoid layout thrashing and related issues. React isn’t immune, but these problems are typically easier to handle.
- Other features: Implementing useful capabilities from scratch, like lazy loading parts of components (for example, suspense) or building hybrid apps with server-side rendering, requires significant work.
I'll argue that nowadays, if you want to use vanilla JS with templating support, lit-html (not the full framework, just the template part) is a much better choice than Backbone.
fny
3 months ago
The example is also unrepresentative of anything meaningful. TodoMVC[0] is the classic point of comparison, and the Backbone version is a nightmare to grok compared to React[2].
Who wants to maintain this nightmare? https://github.com/tastejs/todomvc/blob/gh-pages/examples/ba...
Devs love to invoke Chesterton's fence but somehow forget about it when looking back on "the good old days."
What's worse, there were never good old days for frontend. It always sucked, and now it still sucks--just far less.
[0]: https://todomvc.com/
[1]: https://github.com/tastejs/todomvc/tree/gh-pages/examples/ba...
[2]: https://github.com/tastejs/todomvc/tree/gh-pages/examples/re...
ricardobeat
3 months ago
What you see as a nightmare is really straight-forward code from another perspective. It just looks very unfamiliar. Yes, it feels raw, it is verbose, it's imperative and not declarative, but the entire app lifecycle is there to see.
You can easily tell what every function is doing, including the library ones, and magical behaviour is kept to a minimum. It could be easily maintained 20 years from now, as you have a very thin layer over DOM manipulation and Backbone itself can be grasped and maintained by a single human.
One could argue that React leads to better development velocity, but from experience I can say that reality is not that simple. The initial speed boost quickly fades, instead a huge amount of time starts being allotted to maintenance, updates, workarounds, architecture and tooling as complexity compounds.
aniforprez
3 months ago
I do not want to work with all the untyped strings and random class selectors. I'd say the code is easy enough to read but nigh on unmaintainable.
ysavir
3 months ago
That's all true, but I think the article's point still stands: React trades one set of compromises for another, and regardless of the tool used, software engineers using that tool have to do a lot of lifting to get the tool to work. It's not a question of whether react is better than backbone or vise versa, it's a question of whether we software engineers, as a group, are emphasizing the correct compromises, and what takeaways we can make from examining the compromises of today's popular tools.
cloverich
3 months ago
I definitely do a lot less lifting with React than with jquery or backbone; like OP I also used all three (and others) in production, and my React sentiments at the time seemed to be relatively common: React felt like a breath of fresh air. In particular, counter point to the article, i loved that i could do something relatively complex, relatively easily, but still pop open dev tools and understand what was happening. I think tis great new libraries and concepts are sprouting but imo looking back wont help; browser javascript has come a LONG way obviating a large chunk of the reason we were all using jquery in the first place. Basic CRUD does fine with server side rendering, and is easier to test and maintain. Using that until it hurts is a solid strategy for avoiding react if thats ones goals.
The reality is stateful UI is complex on its own. Then JS tooling is complex (byo typescript and std lib). Then UI is something everyone sees so the whole company has opinions about how it should look. Mush it all together and FE development is rough. React is a punching bag because its been dominant so long. Id welcome the next phase when it arrives. But building toy apps with aged technology imo wont bring to light any unturned stones. Id recommend researching the plethora of real code and discussions that have beaten this horse to death on the open internet instead.
laurencerowe
3 months ago
> my React sentiments at the time seemed to be relatively common: React felt like a breath of fresh air.
This was exactly how I felt. I building a Backbone app around the time React was released. It was only around 2600 lines of JS at the time but event handling and state management already felt like a tangled mess.
Porting it to React was a huge improvement even at that scale and really paid off over the next 5 years of development.
throwawayffffas
3 months ago
The point would me much better served if the article compared react from 2014 to react today.
As others have noted working with react after having worked with backbone, jQuery and ember felt like a breath of fresh air.
It felt that was we were doing was same again, and I would argue understandable. 11ish years later cruft has pilled own to dev experience detriment.
echelon
3 months ago
The job is to deliver complex software with ever changing requirements with a fungible team of engineers.
I'd say React is doing swimmingly at that job description.
For small, artisanal projects, there are lots of other choices and priorities.
I'm merely reiterating the blog's thesis.
qudat
3 months ago
Agreed. You want to run htmx at a company where the business requirements change every month? Good luck but you’re going to end up rewriting it and have a much harder time hiring.
flufluflufluffy
3 months ago
Which is the case for every library ever written
smrtinsert
3 months ago
There's a world of options away from React today that have those features. We can't pretend only React has them.
diegof79
3 months ago
Agree, but the article was about comparing React and Backbone.
There are a gazillion of options that resolve the same problems: Vue, Svelte, Solid, Lit, etc.
Backbone was born as better code organization on top of jQuery and CoffeeScript. It never attempted to solve these issues.
kdazzle
3 months ago
I think Backbone was a bit before Coffeescript.
Haha, coffeescript was so hot for a minute
smrtinsert
3 months ago
The raw jquery version looks better to me: https://justpaste.it/3pz1n
ironmagma
3 months ago
There are essentially infinitely many JS frameworks. You’ll have to recommend one or two to be taken seriously.
smrtinsert
3 months ago
Even the jquery version looks better: https://justpaste.it/3pz1n
But to keep in the good graces of our thought leader overlords, let's start solid or svelte.
Muromec
3 months ago
Vue.js is better react without hooks bullshit and with actual reactivity. Very nice, stable and mature.
mcv
3 months ago
I too prefer Vue over React. I still haven't checked out Svelte, and I'm completely over Angular by now.
React looked great when I first used it for something really small. It looked horrific when I used it on a massive project with ridiculous amounts of data and tons of middleware. Although the real horror was the useEffect spaghetti. Vue keeps looking reasonable in every project I encounter it in. Even when people use it poorly, it's never Vue itself that's the problem. Well, maybe when people start working around the reactivity. That can get really bad.