3 ms·
This is hands down the most nuts example I have ever seen used to make a point about code. A problem that I have never seen before, an extremely complicated de
by thomashop 5y ago
This is hands down the most nuts example I have ever seen used to make a point about 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} />
}
- kristopolous 5y agoIt's horizontal message passing. Your example is still hierarchical. About the classes: that chapter was written before they decided to change almost everything for the nth time. I'm glad you disagree btw. If everyone agreed with me than honestly, I'd not be pushing hard enough.
- thomashop 5y agoCould you give a piece of usable code that highlights the problem? I really did not understand the point you are making from the example you gave.
- kristopolous 5y agoI'll consider rewriting it. That section was about doctrine and aesthetics. For instance, you were talking about the functional component way of writing react, or how I talked about "If reality falls outside the doctrine and really can't be denied then instead of fixing the assumption more often the orthodoxy is amended. A new wing in politics, a new testament in religion, a new movement in the arts, and a new version in software. It permits the avoidance of admitting the failures of orthodoxy while permitting a mechanism to address its shortcomings." I don't think we'll come to an agreement on this and that's fine, it means I am staking a clear and controversial position which is my goal. Honest people can disagree and I really do appreciate your honesty. Thanks
- thomashop 5y agoI was just asking for a simple code example not a philosophical debate about assumptions, orthodoxy and doctrine. Isn't it possible to connect your abstract ideas to a real world example? And why create en extremely obfuscated react class implementation of something that can be done in 3 lines of functional react code?
- deleted 5y ago[deleted]
- kristopolous 5y agoSure. All of them can be organized as hierarchies and that's the point, the organization is codependent with the communication. Let's say you have things with locations and a map (scooters, restaurants, hidden gold, whatever). You click a thing, it highlights it on the map. You click the map, it highlights a thing. The obvious to me way of doing this is singletons (or globals). You've got some routine itemhighlight(thing) or mapcenter(thing) and you generate the things on the page and use something simple like html data attributes to pass things around. In react there's a fairly unorthodox hack I've got to do things like this but normally you'd have a map component and then some list component with item components. Then when you tap the map, the stuff is passed up to a container component that gets passed to the list component that goes back to the item component, so long as you create some connections for that to happen. Everything goes up and down the hierarchy. You don't just directly talk horizontally. Now sure, there's arguments for and against both approaches and they are as contentious as type systems and editors. But the question was about the "scolding nanny". Without react you can do both approaches, the first of which requires competency and skill to do well without creating a mess sure. But in react you are precluded from doing the first unless you wrangle it and work around the framework. It disciplines and limits your freedom. I understand corporate hierarchies, pecking orders, and reasons for doing this. I'm a true anarchist though and that limitation really pushes my buttons. Given all that, I use react regardless because I first and foremost try to be responsible adult and think it's the current most popular and professional way to do things for the day I'll eventually move on and hand over my code to someone else. But I fucking hate it. It's a seething and very unhealthy vitriolic hate.
- nemothekid 5y ago>Could you give a piece of usable code that highlights the problem A shopping cart. The cart state exists in the header of the web page, but the "add to cart" button exists on the product description, far away from the cart. Ultimately, I think, it ends up being a question about state management which is always the hardest part of UI frameworks IMO
- thomashop 5y agoBut a shopping cart is just a piece of state which you modify through an event listener to a button which in turn updates the UI again. These days you can do it with a useState or useReducer hook but there are countless ways to implement it, react or not.
- nemothekid 5y agoBut where does that state live? I imagine GP would like to live on the `Cart` component, but since the Add to Cart button isn't a child of the Cart component, you would have to "pass up" some connector. Alternatively you would just have the state live in a common ancestor of both (or at the Root) but I imagine that GP doesn't like that either (global state).
- pjgalbraith 5y agoTo me it seems obvious that React would be hierarchical. It is a view layer that creates a virtual DOM, that then gets rendered down into the browser DOM. Which is hierarchical. Horizontal message passing is really a state related issue and lives outside of React. You can manage your state however you want and then wire up the components however you want. Since those two things are separate concerns. Although there are a ton of options in the ecosystem to do that.