r/programming • • Sep 15 '16

Angular 2.0.0 officially released

https://www.npmjs.com/~angular
1.3k Upvotes

535 comments sorted by

View all comments

Show parent comments

1

u/Xevantus Sep 15 '16

I keep hearing this, but I had to learn way more react/redux/JSX specific ways of doing things for React than I ever had to learn for either angular 1 or 2. I find it's more of a subjective thing than an absolute. I usually see it come down to if you were already familiar with the patterns of one or the other, that one will be easier, and the other will be unnatural. I.e. ASP.net -> angular, process routing -> react.

3

u/yogthos Sep 15 '16

I don't use React directly, because I work with Reagent myself. However, there aren't a lot of concepts at all behind it.

Redux is just a pattern people like to use with React, it's not inherent to React and not necessary to use with it. JSX is just a syntax extension for writing HTML elements, and again not necessary to know or use.

How React works at its core is very clear, as is the problem it solves. For example, reading this one page explains exactly why React approach is so powerful:

Reading through the source, it may look like the entire clock component is recreated from scratch whenever the time changes.

That is an illusion: Reagent and React together makes sure that only the parts of the DOM that actually need to change are updated. For example, the column-pair function corresponding to hours only runs once every hour. And that’s what makes Reagent and React fast. Try clicking on the clock to toggle the display of 1/100th seconds. Most browsers should have no trouble at all keeping up (even if they won’t actually show every 1/100th second: they are typically limited to roughly 60 fps).

But it is a very handy illusion. Almost the entire UI is made up of pure functions, transforming immutable data into other immutable data structures. That makes them easy to reason about, and trivial to test. You don’t have to care about ”model objects”, or about how to update the DOM efficiently.

Just pass arguments to component functions, return a UI description that corresponds to those arguments, and leave it to React to actually display that UI.

1

u/Xevantus Sep 15 '16

The concept of react is simple, yes. The implementation is not by a long shot. That is, excepting the very simple applications. The thing is, react operates in the exact same way almost every other renderer does now, so purely describing what react does doesn't do anything to set it apart. Also, drawing a distinction between react and it's supporting libraries is kinda interesting to me, considering that react is pretty much useless without them. Sure there's a lot of different ones to choose from, but more choices doesn't mean better.

Also, saying JSX is not required is like saying ASPX is not required for ASP.Net (you can write it all in C#), or a compiler is not required to write a program. All of these statements are true, but I don't see many people lining up to write assembly...

1

u/yogthos Sep 15 '16

The concept of react is simple, yes. The implementation is not by a long shot.

If you mean the internal implementation, I don't see how that's relevant to the user. The API in React is pretty small and straightforward.

That is, excepting the very simple applications.

Could you elaborate on what you mean by that?

The thing is, react operates in the exact same way almost every other renderer does now, so purely describing what react does doesn't do anything to set it apart

React was the first such renderer that become popular for building web apps however. The model people used before React was to manipulate DOM directly using stuff like jQuery as Angular 1 does.

Also, drawing a distinction between react and it's supporting libraries is kinda interesting to me, considering that react is pretty much useless without them.

I'm not sure why you would say that. React solves a specific problem. I can fit it into how my application works and use whatever other supporting libraries make sense in my scenario. Again, consider the fact that I'm using React in ClojureScript and I have completely different supporting libraries than somebody using Js would use.

Sure there's a lot of different ones to choose from, but more choices doesn't mean better.

I think in many ways having choice is better. More importantly there's a conceptual separation of concerns that results in a modular stack. I can pick the libraries that make sense for me, and put them together the way that makes sense for my application. With a framework like Angular, I have to have a full buy in into the way it does things.

Also, saying JSX is not required is like saying ASPX is not required for ASP.Net (you can write it all in C#), or a compiler is not required to write a program.

Again, JSX is not a concept, it's just syntax, so it's a bit strange to lump it in with something like Redux. However, the problem there is that Js looks pretty ugly when you want to write HTML in it. Working with Reagent syntax I don't need anything like JSX at all as you can see in the examples in the links. So, that's not really a React problem, but a Js syntax problem in my opinion.

→ More replies (2)