r/angularjs • • Jun 30 '18

Why React is bad.

Here's why I think Angular is much better than React for creating SPAs.

React is not a framework like Angular is. It doesn't provide a comprehensive, one stop solution for all the things that you need for building an SPA. Often you will hear that React is 'un-opinionated' and that it allows developers the freedom to use whatever technologies they want alongside it. In practise, this means having to either constantly reinvent the wheel, or else employ a hotchpotch of third party libraries and be completely at the mercy of their maintainers.

Third party libraries may be buggy and there's no guarantee that fixes will be swift, if they even happen at all. Plus, they may be deprecated without any notice and you have to hope that they will work together successfully.

For state management Redux is the defacto standard. Redux is, in my view, seriously flawed. Firstly, why do you need to have a store in your client side at all? Is that not what the Database is for? In an SPA, the URL should be the single source of truth and the entire state of the app should be derived from this, using data fetched from a service. When you use Redux in an SPA, you need to work to keep the store in sync with the URL. This is a lot of work for no obvious benefit.

Another problem is that it risks storing stale data. Once the URL changes, all the existing data is potentially stale. There is no value in storing data across requests. If you want to cache data, the browser will cache your requests. Invalidating caches is notoriously difficult to do - why on earth do we bring this problem to client side development!

Redux also introduces Race conditions. If we make multiple requests to the server in quick succession, the Redux store has no way of knowing in what order these were made and given that they can return in any order, it is quite possible that the page we are looking at could be overwritten by the data from an old request! More detail about this problem here:http://blog.richardhunter.co.uk/index.php/13

The Redux store does NOT represent the current state of your app. It probably contains it, but it contains an awful lot besides and working out what is the current state and what is old state involves a lot of error prone work.

The next problem with React is that it does not support Dependency Injection. https://en.wikipedia.org/wiki/Dependency_injection DI is essential for building a complex enterprise grade application. The main benefits of DI are that it makes object creation a much cleaner process and it decouples dependencies from their implementation. If the last point is unclear, what it means that when you build an object you can supply completely different objects for any particular dependency. This is useful in testing where you can swap in mock objects for dependencies and thus test your objects in isolation from each other. With React, you have to rely on monkey patching or else test much larger chunks of your code at a time.

In React, you have to pass any dependencies down to components through props which can mean that a component has props that it doesn't actually use itself but just has them so it can pass them down to child components. You can use the Context for surfacing dependencies in a component but this is very much a poor man's DI imho.

There are other things about React that I don't like, but I don't want to extend this post too much. In particular PropTypes seem like an extremely feeble way of doing static typing and really typifies what is bad about React.

React isn't just different for not being a framework - it's worse. It is hopelessly inadequate for doing the job that it is supposed to and just results in messy, buggy, and inadequately tested applications.

I think the reason that React is more popular than Angular is because Angular lost a lot of good will during the shift from version 1 to 2. Maybe the Angular team didn't cover itself in glory, but I think the decision was the right one as the new Angular is much superior to the old one. It's irrational to dislike Angular because of these events but maybe a lot of developers are irrational.

0 Upvotes

122 comments sorted by

View all comments

3

u/XPTranquility Jun 30 '18

Just here so I won’t get fined.

0

u/[deleted] Jun 30 '18

[deleted]

1

u/[deleted] Jun 30 '18

Yes, the problems of race conditions can be solved by writing more code: That's called 'bug fixing'. Nor does Redux advertise these problems, and in my case I only learned about them when I encountered them myself. Redux Observables are the solution imho. Angular of course is built with Observables tightly integrated into it. Apparently the Angular team understand this problem and have picked the correct solution.

Your arguments about performance boils down to: React is fast and Angular is not. But that needs some serious metrics behind it for it to be true. There have been numerous performance comparisons carried out on React and Angular and I've yet to see any conclusive evidence that one is dramatically superior to the other in terms of performance.

4

u/prof_hobart Jun 30 '18

So the issue here seems to be that you once used Redux, didn't know how to deal properly with async requests, created a bug in your code and blamed Redux for not holding your hand enough.

As I've explained elsewhere, there's plenty of well worn approaches that don't need observables to solve the problem.

Observables are find, and the fact that Angular provides a lot of this out of the box rather than you having to think about it yourself is great for some people.

But for others, the flexibility of approach that you get when you piece together a React-based solution is also an advantage.

1

u/[deleted] Jun 30 '18

No, you can use Redux exactly as recommended in the docs and have this bug. The problem is known about by Dan Abramov himself and he suggests ways to overcome it. The point is, this bug shouldn't be there to start with. https://stackoverflow.com/questions/37738268/how-to-avoid-race-conditions-when-fetching-data-with-redux

6

u/prof_hobart Jun 30 '18

https://stackoverflow.com/questions/37738268/how-to-avoid-race-conditions-when-fetching-data-with-redux

Yes. That would be a pattern for dealing with async. It's not a bug that a particular library doesn't do that magic for you - it only becomes a bug if your code doesn't then add the magic that your chosen library didn't (As Dan said "The problem is due to suboptimal state organization.")

You can argue that library A might be better for you than library B because it makes easier for you to implement a particular pattern, but that's vastly different from claiming that it's a bug in library B because it doesn't do it - if that's not part of library B's remit, it's just up to you to add it yourself.

-1

u/[deleted] Jun 30 '18

Dan's solution doesn't actually remove the problem, it only mitigates it. I disagree with Dan's assertion that if his library doesn't work then it must be your data model that is wrong. Why should the structure of my data have anything to do with whether or not I get a race condition?

As far as I know, the issue isn't flagged anywhere in the Redux documentation (such as the 'Troubleshooting' section?) so it is sitting there waiting to bite someone. The idea that not being able to handle responses coming back out of order is some kind of marginal concern seems strange to me.

5

u/prof_hobart Jun 30 '18

Redux isn't there to solve that specific problem, so why should its docs cover it? Its docs aren't an essay on computer science as a whole, and it's assuming that you've got a fair amount of experience in this kind of thing.

You seem desperate for a one-stop shop framework that spoon-feeds you all of the answers - which is fine, if that's where you are on your professional journey.

But many of us want more flexibility, and realise that this sometime means that we have to do a bit of our own thinking about some of the thornier problems of computer science.

The idea that not being able to handle responses coming back out of order is some kind of marginal concern seems strange to me.

The problem is potentially that you've designed a system where there is such a thing as "out of order" - in most cases, if you're kicking off multiple simultaneous requests, it shouldn't matter what order they come back in.

In situations where it is an issue, there are standard ways to deal with it - which one to pick depends on the nature of the data you're getting back - whether you're cancelling/ignoring the latter responses, overwriting a particular bit of data, checking timestamps etc.

But the point is that you actually need to think about it - the framework isn't going to magically make that decision for you, as it doesn't know your data. It might make some of those solutions easier to implement, but if you're just looking at the framework to solve it for you without doing the thinking yourself, you've got a fair chance of it making the wrong decision.

-2

u/[deleted] Jun 30 '18

if you're kicking off multiple simultaneous requests, it shouldn't matter what order they come back in.

So if the user clicks a button for 'page1', then changes their mind and clicks the button for 'page2' and page 2 appears but is shortly overwritten by page1, that's ok?

2

u/prof_hobart Jun 30 '18

No. Why would it be? And what's this got to do with React or Redux?

→ More replies (0)