Live data from Hacker News

Why I moved from Angular to React

robinwieruch.de

51–60 of 107 posts

Re: Why I moved from Angular to React

#51

How many of you developers who use React and say that JSX is the second coming of Jesus, are also able to produce a semantically coherent HTML document with JSX? It seems to me that React + JSX are perfect for "divitists" and devs who use a h3 because its font-size has the desired value. I'm not being sarcastic, I genuinely can't understand why a good web developer who cares about the meaning of a HTML document shoul…

Well there's nothing stopping you using the right element for the job. But I would argue that the semantics of HTML, whilst useful in a publication paradigm, don't translate as easily to a web application, which is where React shines. I'd also argue that React is not a good fit for something like a blog, or a news site.

This is a great point, and a sword I fell on at my previous employer. React is great for stateful web apps - a blog or a news site have some state, but aren't really that state heavy.

Especially when you have a news site getting millions of views, you simply can't afford 1 second on page load to download, parse, and eval React and your data model for little gain.

I've seen devs that are so infatuated with React and "isomorphism" that they will use it as a hammer for every screw they come across.

Re: Why I moved from Angular to React

#52
post #47

Earlier quoted context omitted.

Yup, I still use knockout because I have components for nearly everything I do.

Do you mix React and Knockout components by any chance? We are looking at moving from Knockout to React and I was wondering how painful this would be. My guess would be that if you are doing all or most of your KO stuff with components, then the switch shouldn't be too bad.

I've done some mixing of Knockout and React. We had a custom datagrid that was taking a long time to bind up all the data with templates. I think it was made almost 8x faster for rendering moving it to a React component. This was a POC project done probably 18 months ago.

Re: Why I moved from Angular to React

#55
post #43
post #37

Earlier quoted context omitted.

As mentionned already, and as Pete Hunt famously talked about in "Rethinking Best Practices" (you can find it on youtube), you want to separate -concerns-, not technologies. Often there is a 1:1 between those things, but not in modern web development. So we've seen a push toward components that mix technologies, but separate concerns. And it's been great.

This is a great explanation. People learnt that mixing behavior and presentation was bad but that was a specific case of a more general rule. In fact - "separation of concerns" is itself a specific example of an even more general rule which is something like "Make code easy to reason about" or "reduce side-effects" or similar. It's hard to give advice that doesn't sound hand-wavy and empty without getting specific. B…

We usually take all software design principles at a face value and rarely think about the reasons why we have them in the first place.

The reason why we need software design principles is because software changes. Software design principles are methods of organising software that make it easier to implement changes.

When it comes to changes it seems that the golden rule that makes things easier for humans is: things that vary together should be together (and things that tend to vary separately should be separate). Its interesting to think about why this is the case, but I'll skip that and take it as an axiom.

There was an article (which I can't recall the URL of) that argued how all the SOLID principles stem from this basic rule.

Single responsibility principle: it follows directly from the above rule: A class should have only one reason to change (keep things that could change separately separate)

Open/closed principle: Interfaces should vary significantly less than their implementations, so that both producers and consumers of those interfaces can vary independently of each other. e.g. Shape can have a method draw that takes a canvas interface: now we can vary both the canvas implementation and the different shapes independently.

Interface segregation principle: don't put too many things in an interface, they might vary differently. Make separate interfaces based on consumer types since change in consumers are more likely to affect changes in the interfaces they use, and having one interface for two types of consumers means two separate sources of change that vary differently.

Map / filter vs for loops is simply this principle applied in the small. The code to initialize an empty data structure, iterate through all the elements applying a function and then store the resutls in the data structure is always the same. The only thing that changes is the function that defines the transformation. Since its a concept that is very common and never changes, it should be separated from the transformation itself (which changes often and depends on the problem domain) and be given a common name (map)

It then follows easily that separating the component template from the code that manages component state doesn't really help. Its fine in server-side languages where the template is simply the final function in the data transformation pipeline for that request, with multiple potential views on the same data (html, json, xml etc). However, on the client side most of our code manages changing state closely tied to the DOM based view: for example, the sort column and sort direction of a table, or the current item selection, etc. The kind of state we keep is directly tied with how we present things (sortable table? => sort column and sort order; expandable tree? => expanded/contracted state for all branches, etc). As our view/component requirements change, the state we keep for it (and the way we manage it) also changes.

And since things that vary together should be together...

Re: Why I moved from Angular to React

#56
I'm glad this conversation continues to evolve, particularly now that Angular(2?) has stabilized.

Practically speaking though, I'm evaluating high-level frameworks like Blueprint, Clarity, and Element, vs. the prospect of becoming a bespoke framework provider myself (probably not).

If I'm starting off with a respectable set of components, then I can adapt to the lower level libraries as necessary.

Re: Why I moved from Angular to React

#57
post #31

In other news: Why I moved from table salt to sea salt.

If you feel the topic is inappropriate for HN, flag and move on. Snarky, dismissive comments like this don't add constructively to any discussion.

It's pretty funny tho, I thought immediately of Top Gear

Re: Why I moved from Angular to React

#58
post #37
post #27

React comes with its own syntax to build components called JSX. In JSX you can mix up HTML and JavaScript. Additionally people often use inline styles in their elements. It is like adding CSS into the mix. This really scares me. We spent a lot of effort removing inline styling from HTML with CSS, and yet it still creeps into our HTML. We also have created a lot of "template" languages (e.g. PHP, Python, ERB, etc.) mi…

As mentionned already, and as Pete Hunt famously talked about in "Rethinking Best Practices" (you can find it on youtube), you want to separate -concerns-, not technologies. Often there is a 1:1 between those things, but not in modern web development. So we've seen a push toward components that mix technologies, but separate concerns. And it's been great.

[deleted]

Re: Why I moved from Angular to React

#59
post #27

React comes with its own syntax to build components called JSX. In JSX you can mix up HTML and JavaScript. Additionally people often use inline styles in their elements. It is like adding CSS into the mix. This really scares me. We spent a lot of effort removing inline styling from HTML with CSS, and yet it still creeps into our HTML. We also have created a lot of "template" languages (e.g. PHP, Python, ERB, etc.) mi…

Problem with everything in HTML was that you couldn't split HTML into small meaningful composable parts.

JS is actual programming language an you can split out styles to separate style library without using .css files.

You could also split out render function (that uses JSX) or its parts to separate file. But you'd rather keep it close to logic that interacts with it and keep the whole component, logic plus presentation small enough to understand with a glance.

Re: Why I moved from Angular to React

#60
I've used ExtJS, Backbone, CanJS, Angular, Polymer and React commercially. To me, React is a more complex alternative to Google's Polymer framework.

In React, a component is made up of code which has HTML inside it.

In Polymer, a component is made up of HTML which has code inside it.

They're actually the inverse of each other but the result is almost exactly the same - Both libraries allow you to build components which contain other components and both provide clean encapsulation.

One of the reasons why I have a slight preference for PolymerJS is that it's much simpler and works with existing HTML concepts (they didn't need to invent a new debugging panel, a new DOM model, a new approach to CSS styling or an advanced state management architecture like Redux to make it work) - Instead, they leveraged existing web technologies. For example, Polymer provides really nice CSS style encapsulation. In PolymerJS, the tag only affects the component in which it's declared (potentially including sub-components but not parent components).

It makes CSS really easy to use/maintain without actually reinventing it. You can do cool stuff like allow a sub-component's style to change automatically as you move it from one parent component to another. You don't need any special module or library or special styling logic; just a tag declared at the appropriate level in your component tree/hierarchy is all you need.

That said, the React community is massive and because of this, there are tons of modules and tools around it so it's hard to beat now - It seems that pretty much every problem that React has introduced has since been fixed.

Post reply on HN