News for hackers. Stuff that matters.
Re:Vue.js: the good, the meh, and the ugly by allover on Thursday July 05, 2018 @05:29PM (#17466997)
> If plain, idiomatic React so great, why does every semi-complex React app end up bringing in a separate state management framework like Redux or MobX?

Sadly it seems that's mainly been cargo-culted. It's not the case that React+Redux is the equivalent to say Angular, but by some unfortunate accident due to Facebook's announcement of Flux, and then the hype around Redux as a 'better Flux', people started assuming React+Redux is what is needed to build a React app.

Meanwhile Dan Abramov, Redux creator says [1]:

> Flux/Redux is meant for big apps with complex nested UIs that have many independent parts but share common caches of data.

That's not "every semi-complex React app". In most "semi-complex React apps", most state can be derived from the route (e.g. react-router) or is relatively local. Redux is not required.

[1] https://twitter.com/dan_abramov/status/732719257579065345

Re:Vue.js: the good, the meh, and the ugly by atombender on Thursday July 05, 2018 @06:43PM (#17467490)
There's unfortunately a thin line between cargo-culting and attempting to follow the mainstream.

As developers we can't all be building tools. We choose tools that others build for us, so that we can get our job done. Soemtimes I'm interested in going "one layer down" and build tools, but it's almost always a distraction; we want off-the-shelf products like React and Redux. We need to pick stable tools that promise some sort of longevity. We also need to pick tools where best practices and idioms have been established.

To do this we have to trust someone else's opinion and try to gauge which solutions have the best prospects. This means not just evaluating software based on its own technological merits, but also listening to what "the community"/"the industry" seems to be rallying around; you don't want to be stuck using a library that nobody is maintaining, just as you don't want to be stuck using something that's just badly designed.

When we started using React, there was no state management framework available, and everything was handled somewhat ad-hoc. Then Facebook described Flux, and we realized they were onto something, so we started using their patterns, with some simplifications where theirs seemed overly complicated. Then Redux came along and seemed like a better way to do things.

At each point there was uncertainty about what best practices and "idiomatic" solutions would turn out to be, because the technology was immature. I don't think anyone was cargo-culting. It was just that a lot of people were busy trying to create things, and when there isn't clear guidance, and the alternative is going back to Backbone or jQuery or something, then you just forge ahead, trying to do fit the pieces together.

Re:Vue.js: the good, the meh, and the ugly by allover on Thursday July 05, 2018 @07:02PM (#17467610)
But if you looked at the official React docs the answer was always 'setState' and embracing components, that was the whole promise of React to begin with. Not once did the React team/docs ever say you needed Flux to build a React app. All of those answers you got were cargo-culted from the community.

Can you really look at where the community is, the perception that still exists that React+Redux is necessary, projects like redux-form (that now admit Redux was a poor fit for forms) and honestly say no cargo-culting happened?

Sympathy for 'attempting to follow the mainstream' though, I understand that. Personally I stuck with Backbone for years longer than most, avoiding the Angular/Ember wars, and the early days of React+Flux til the React ecosystem had matured a little, before jumping over to React at which point it was clearer that Flux/Redux were being misused.

Re:Vue.js: the good, the meh, and the ugly by jakelazaroff on Thursday July 05, 2018 @11:37PM (#17468669)
The official docs originally described React as "the V in MVC" [1], so the assumption about needing another layer to handle state and business logic didn't come from nowhere.

The claim isn't that there's no cargo cult around the React ecosystem — but not everyone writing React code is approaching it with experience, which means they try to pick up best practices from other people. That's not "cargo culting"; it's a reasonable thing to do when you have to solve a problem you don't know how to solve!

Ultimately, people aren't being "tricked" into using these tools. They proliferate because they solve real problems people have, and a lot of people would rather work with a popular and well-documented solution (with known advantages and drawbacks) than trying to forge their own path and seeing how it goes.

[1] https://github.com/facebook/react/pull/7012

Re:Vue.js: the good, the meh, and the ugly by atombender on Thursday July 05, 2018 @07:16PM (#17467686)
Can we blame all the bloggers who take upon themselves to explain what the best practices is? Absolutely. There are also projects (like React Forms and React Router) that clearly led down a path of confusion. But it's hard to blame the developers who read those blogs and try to figure out what they should be doing.

I never got the impression, even from the start, that setState() was a good solution, by the way. But it's not like the React authors were completely sure of where the right design was, either. Flux, for example, as it was originally described, appears completely overdesigned at this point. The good design is to be found in Relay and GraphQL.

Re:Vue.js: the good, the meh, and the ugly by allover on Thursday July 05, 2018 @07:41PM (#17467819)
> Can we blame all the bloggers who take upon themselves to explain what the best practices is?

It's not really about blaming bloggers.

It's really on software team leads and senior engineers to not just follow blog posts blindly. They should be pushing back on bad advice like redux-all-the-things, because to a senior software engineer the tradeoffs of something like Redux should be fairly obvious.

> The good design is to be found in Relay and GraphQL.

Nah again, good example to question what you read/hear.

GraphQL is great from a front-end point of view but complex to implement in the backend, so it really depends on your use-case whether that backend complexity is worthwhile.

Re:Vue.js: the good, the meh, and the ugly by _hardwaregeek on Friday July 06, 2018 @01:14AM (#17469040)
Could you provide a source for the maintainers of redux-form admitting that Redux was a poor fit for forms? I'm inclined to agree and am kind of interested to see their reasons.
Re:Vue.js: the good, the meh, and the ugly by allover on Friday July 06, 2018 @05:24AM (#17470038)
Yep, sorry I should have included the reference. This post is by the redux-form creator, in which he states why it was a bad idea, and announces its 'spiritual successor': https://codeburst.io/final-form-the-road-to-the-checkered-fl...

> Also, everyone high up in the React community, including both inventors of Redux [1], say that Redux is not the best place to keep form data. Oops.

[1] https://github.com/reactjs/redux/issues/1287#issuecomment-17...

Re:Vue.js: the good, the meh, and the ugly by acemarke on Friday July 06, 2018 @11:07AM (#17472001)
Now, it _does_ depend on your use case.

An isolated login form? Yeah, no point keeping that in Redux - it's not being shared, it's not being persisted, there's no real need to track the history of changes. But, there are certainly situations where you might want to keep some form data in Redux.

As a specific example from my own app: we show some polylines on a 3D globe, and allow the user to edit them. We need to be able to live-update the point locations and labels on the globe as the user edits them, allow resetting edits, and still be able to show the original values elsewhere in the UI. Keeping all that data in Redux makes it easy to do so.

The Redux FAQ has a list of suggested rules of thumb for deciding what state should go in Redux: https://redux.js.org/faq/organizing-state#do-i-have-to-put-a... .

Re:Vue.js: the good, the meh, and the ugly by mosdl on Friday July 06, 2018 @04:27PM (#17474847)
You can achieve all of that with a singleton that is shared and some events (and do some of your own batching). No need for another dependency and you save bloat size.
Re:Vue.js: the good, the meh, and the ugly by acemarke on Friday July 06, 2018 @06:58PM (#17475753)
Well, the whole app is built around Redux in the first place :)
Re:Vue.js: the good, the meh, and the ugly by drunknhik on Sunday July 08, 2018 @07:19AM (#17483226)
To me this underscores the most unspoken point. Redux is meant for when you specifically want to build your app around redux. It's not meant to tack on some global store to an existing UI. It is UI agnostic way of separating your business logic and side effects from the UI iself (which could be react, vue, angular, whatever)
Re:Vue.js: the good, the meh, and the ugly by acemarke on Sunday July 08, 2018 @09:03AM (#17483573)
For the most part, yeah.

Now, the other app my team works on is built with Backbone/Marionette. We've introduced React and Redux to it, and are progressively refactoring over time. It works, although we've got some rather ugly code in several places (some data is in Backbone collections, other data is in Redux, and occasionally some bits of data are mirrored in both places).

I wrote about some of the techniques we're using to integrate them here: https://blog.isquaredsoftware.com/2017/07/react-redux-backbo...

Re:Vue.js: the good, the meh, and the ugly by bananadonkey on Thursday July 05, 2018 @07:50PM (#17467859)
As one of a small group of maintainers of the build tools of our most complex app, I can concur with this. Yesterday I spent 4 hours fixing a single build/parse issue between dev and prod.

I also spent just 1 hour completing multiple RFCs in another app built with create-react-app using redux/connect as a purely syntactic-sugar state propagation layer.

I love the complexity and feeling of fulfillment for triumphing in the former scenario, but it is definitely much more of a distraction than anything else.

Re:Vue.js: the good, the meh, and the ugly by ppseafield on Thursday July 05, 2018 @09:54PM (#17468356)
I remember when I first started to try and learn React there was only a handful of words and a vague diagram from Facebook about its Flux architecture. And after that there were many, many similar state management libraries. That some in the community picked a smaller one that had in-depth documentation and emphasized stateless / functional style programming is not terribly surprising.

IIRC there were a lot of comments about having to pass props to children constantly (without using a state management library). Seems like it's a lot easier to not use a state management library now that an official, non-experimental Context API exists. But remember, this was only added a few years later.

Re:Vue.js: the good, the meh, and the ugly by ilovecaching on Thursday July 05, 2018 @05:43PM (#17467104)
Agreed. Cargo culting is the main issue. The solution is to try and remain unbiased, and not look for direct synonyms between two very distinct approaches to managing user interfaces.
Re:Vue.js: the good, the meh, and the ugly by olfactory on Thursday July 05, 2018 @10:34PM (#17468457)
Well, FWIW js is not the most friendly language for functional programming. I'd argue that the trend toward immutable.js and redux occurred partly because rest/spread syntax was/is relatively confusing, and so immutable patterns without a library feel less elegant until one really groks the somewhat visually opaque semantics of the rest/spread syntax.

Redux also offered a simple approach to the "action bus" idea from Flux, but omitted first class async support, etc. React itself also somewhat overlooked async patterns, which created the idea that their absence was by design and so an additional (opinionated) library was appropriate.

In sum I'd argue that React actually fights against js quite a bit and that it will truly come into its own once reason gets more mindshare.

For those of us who invested heavily in react as all this was becoming clear (and being ironed out) I hope we learned enough to allow better decision making in the future.

Also, React has a few "on by default" performance enhancements that are a bit conceptually confusing and create something of a mismatch with the functional approach.

But still it's difficult (and unpleasant) to imagine the world without React.

Re:Vue.js: the good, the meh, and the ugly by jbergens on Friday July 06, 2018 @07:42AM (#17470591)
Also, MobX is for most devs easier to understand and use than Redux and more similar to Vue and Angular. I think most small react projects should start with no external state management or mobx and only switch if they need it. Unless they already know redux very well and think it suits their project.
Re:Vue.js: the good, the meh, and the ugly by Globz on Friday July 06, 2018 @11:18PM (#17476774)
Just to add some weight to your opinion about Redux being cargo-culted take a look at this video

https://youtu.be/S6lwJ6Rixnc?t=6m