by kristopolous · 5y ago · 0 comments
It doesn't actually empower anything - it acts as a scolding nanny prohibiting people from making things explode.
It does this by imposing a narrow opinion about things that's constantly changing with each release as it herds the programmer through very specific and alarmingly complicated ways of doing things.
It's fundamentally a tool of oppression, not one of expression and one of coercion and not liberation. I hate it so much.
Before react I hated UI programming so much. But the way react deals with state makes it so much easier to build and maintain complex applications.
All you have to do is define how your application responds to any given state and provide explicit controls for asking to update that state. If you do that correctly, your application will be predicable and easy to reason about.
The biggest challenge is it's just not the normal imperative programming model that most devs are used to. It takes time and understand to do correctly, but what doesn't?
I'll readily admit to being a passionate radical about this stuff. The things I have to say are basically just a bunch of bomb throws and I don't feel this is the appropriate place nor do I have the requisite time.
Rest assured, I've put in a considerable amount of time and effort into my thoughts on the matter and we'll likely disagree, but let's not do that here.
Real question; not being snippy...
I didn't think React had any state management included. A lot of people I've spoken to seem to use Redux, a third party library for handling state.
Is my understanding incorrect?
However, that _is_ limited in that you can only access state inside the current component, or pass it down the tree as props/context. If you need to access data broadly across the component tree, or the data itself does not lend itself to a tree-shaped usage pattern, or you need to minimize the number of components that re-render when you update, or you need to use it _outside_ the component tree, then you may want to look at an external state management library.
I've talked about the tradeoffs in these approaches numerous times:
https://blog.isquaredsoftware.com/2021/01/context-redux-diff...
https://changelog.com/posts/when-and-when-not-to-reach-for-r...
https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-...
All that said: React makes writing an application with any meaningful amount of complexity _vastly_ easier to do than trying to do it with either preceding UI frameworks (AngularJS 1.x, Backbone, etc) or jQuery. It isn't perfect, but it's well-suited for a wide range of application development use cases.
Redux takes that to the next level but is based on similar principles of "reactive" programming. For complex state heavy applications it's extremely powerful, but often overkill for many smaller applications.
But I also think 'react' means two different things. One the one hand, it's "just a library". In industry, it tends to mean... react + JSX + react-router + redux + react-this + react-that + react-redux-this-and-that all tied together with create-react-app. Plus its own command line tools, and browser plugins. It starts to feel very much like a framework then, if not a platform of its own.
On another note, most of these complaints, IMO, aren't even specific to React. We were barreling down this future during the days of jQuery.
ReactJS has a wildly inflexible architecture that aggressively forces their users to conform to an orthodoxy. As an example let's say we have the following code
function C() {
var A = {
something: () => console.log("hi")
},
B = document.createElement('div');
B.onclick = () => A.something();
}
This small snippet of code violates "best practices" in react and thus is almost, but not quite impossible to do.See the problem here is that B and A are directly interacting with each other. If we were to map things in react-land, they would show that C has "children" of A and B and here A and B talk to each other "horizontally" which is heretic to the purity of the orthodoxy.
The hierarchical nature here is an unwavering assertion about the world. Essentially the claim is as follows:
C
/ \
A---B
The A <=> B is what forces us to wear a scarlet letter and live on the edge of the town.Therefore we no longer solve a problem. Instead, we are imposed upon us an aesthetic puritism do to a natural belief of "props down, events up". A popular way to do this basic programming technique that's been readily available in effectively every programming language since the first digital computer (Plankalkül had it in 1942) is the usual suspects either add "a new testament" to the orthodoxy, in this case with something called "redux" or figure out an acrobatic way to comply.
Let's do the second. So we need to "pass down" things that will "pass up". We have a solution, now we must go backwards, first we will go into "classes" to make things more orthodox.
class A {
componentDidMount() {
this.props.connector(this);
}
something() {
console.log('hi');
}
render() {
return;
}
};
class B {
render() {
return <div onClick={ this.props.onClick }>
}
};
class C {
constructor() {
super(props);
// here's our connecting function
this.connector = this.connector.bind(this);
this.onclick = this.onclick.bind(this);
this.state = {connector: ''};
}
connector(obj) {
this.setState({connector: obj});
}
onclick() {
this.state.connector.something();
}
render() {
return (
<A connector={ this.connector } />
<B onClick={ this.onclick } />
);
}
};
So to simplify this flow A -> B
We now do C -> A -> C -> B -> C -> A
Or as a diagram, we get the following: .---◢ ◣----.
.▶B---▶C--. \
| ◤--'|\ ▼ /
\____/ '►A-'
See how we do multiple round trips passing things through C in order to maintain the hierarchy? This is how we stay within the orthodoxyIf this looks like Ptolemaic astonomy, that's not a coincidence! In Ptolemaic astronomy the assumption of Earth being the center of the universe was enforced as the orthodoxy. As a result you got epicycles upon epicycles because the simpler model was forbidden.
People were so committed to the more convoluted orthodoxy that anyone who questioned it was put on trial for heresy.
Claiming that A -> B was even possible was the crime.
The great success of React is in enforcing a new kind of authoritarianism: it enforces doctrine by explicitly disallowing heretical code.
A problem that I have never seen before, an extremely complicated description, a terrible implementation in react using class components, some weird circular diagrams.
This looks like it's generated by GPT-3.
What is this piece of code even supposed to do?
function C() {
var A = {
something: () => console.log("hi")
},
B = document.createElement('div');
B.onclick = () => A.something();
}
In react: function C() {
const A = {
something: () => console.log("hi")
};
return <div onClick={A.something} />
}I'm glad you disagree btw. If everyone agreed with me than honestly, I'd not be pushing hard enough.
That said,
>The great success of React is in enforcing a new kind of authoritarianism: it enforces doctrine by explicitly disallowing heretical code.
I don't think this is a bad thing, after all the success of Rust is also predicated on explicitly disallowing heretical code that may have been commonplace in C. Constraints lead to more maintainable code, which is ultimately what frameworks these provide. I don't think your complaint is unique to React due to the fact it's HTML that influences that hierarchal design. That said, I'm not a front-end dev, and I my exposure to UI patterns is relatively limited; so I'm looking forward to your eventual book.
Button Press -> State -> Shopping Cart View
Just have the state have a function for dispatching a change to the shopping cart which is passed to the button component and pass the actual state to the shopping cart view.
You can have the state live in a parent component, use redux, use context or go more hacky.
const B = ({onClick}) => <div onClick={onClick} />;
function C() {
const A = {
something: () => console.log("hi")
};
return <B onClick={() => A.something()} />;
}That's the entire point. Software is eating the world, and there's not enough talented engineers. We can't just wish thousands more talented engineers into existence, so instead we have to come up with tools that will make people that only have 3 months of coding school under their belt and money as their only motivation reasonably productive.
If you're a god engineer, you have experience of working around constraints. That's just another one.
An excellent programmer will write excellent code using React, in Java or in C++. It's not about the tool, it's about the one wielding it.
HTML, CSS and Javascript are already extremely high level and capable. Do some xlib programming some day if you want that to be obvious.
So user clicks something -> app state gets changed -> modify DOM in response.
Here's a good description of a framework agnostic approach.
(i'll use this opportunity to plug my project, https://campfire.js.org)
The value of “guardrails” like type checking, borrow checking, and simple APIs is they allow you to turn your brain off when coding. I don’t write code because it’s an artistic expression of self, I write code because it’s a lowish stress job and I need to eat.
In my free time I get some joy out of writing clever code but by far 99% of the code I write I want to be boring.
All crafts have this - the corporate musician working on commercials and tv shows that's just trying to raise a family and "The Artist" that wants a free expression of their very soul.
I'm a slightly crazy person who is passionate about the liberatory potential of technology and how it reshapes society, hopefully as an empowering tool that benefits all. To quote Fred Brooks “The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination."
While you are happily working within the system, doing your job competently, and enjoying the fruits of your labor.
We can still be friends, but I'm going to be that wacky bird pushing the envelope, it's in my very soul and I don't think I can change that.
I think one thing that would help strengthen your stance would be a plausible explanation for why people seem to actually like React and friends so much.
Maybe your experience is different, but I'm often seeing people want to use React or Vue and lament the times they're stuck with JQuery or something more "old-school".