r/programming • • Nov 19 '18

The State of JavaScript 2018

https://2018.stateofjs.com/
164 Upvotes

177 comments sorted by

View all comments

55

u/dpash Nov 19 '18

Interesting that most people say they'd use React again, but the biggest complain is that it has a clumsy programming model. Anyone got an explanation?

53

u/JeffJankowski Nov 19 '18

I think a lot of people are uncomfortable with the data/presentation coupling after having MV* drilled into them for so long.

edit: JSX also feels pretty wrong on first glance

65

u/Sarcastinator Nov 19 '18

after having MV* drilled into them for so long

You mean separation of concern

edit: some of us lived through PHP and IIS Classic VBScript.

15

u/[deleted] Nov 19 '18

You (should) still have separation of concern in JSX / React. It's just sliced differently.

24

u/kyerussell Nov 19 '18

Yeah. "drilled into" felt like a bit of a value judgement, and a bit of a short-sighted one at that.

I still very clearly remember PHP spaghetti code. I don't doubt that a *lot* of PHP is still written like that now. I don't want to re-live that.

Consider Vue. Single-file components with your HTML, CSS, and JS in there. Yet somehow it manages to achieve a separation of concern that JSX seems to really discourage.

I've tried so hard to like React, like one of the cool kids. I'll take Vue over it any day of the week, even though they are 75% the same framework.

17

u/elschaap Nov 19 '18

any day of the week, eve

That;s why I take Angular over both .. since yes ... I like my concerns really separated

2

u/JehovahsNutsac Nov 20 '18

I'm just about to take a React course online and was debating between Angular or React.

A lot of things I read online seems to say React is easier to learn and can do what Angular does. Reading descriptions here of React and the general way it works is starting to make me nervous.

Being a backend developer with C# and Java, Typescript was an attractive bonus with Angular.

Not sure what direction to start on, with all these JS frameworks out there.

4

u/Clawtor Nov 20 '18

I've heard that React was created because of the influx of backend devs into the front end. Personally I find that React maps better to coding because nested components become more like nested functions.

2

u/JehovahsNutsac Nov 20 '18

Huh, interesting way to look at it. :)

Thanks for the input.

3

u/elschaap Nov 20 '18

If you know C# and Java I think Angular will suit you more since it actually looks somewhat like Spring Framework.

But ... why not learn both ... each have their own pro's and cons so it's better to find out which of the two is better for you.

Trying to get to a decision based on Reddit opinions will likely get you to choose nothing because there's always someone having a something against framework X or Y or language Z ... usually without any real argument ;)

→ More replies (2)

1

u/Clawtor Nov 20 '18

One of them you write html in js, in the other it's js-lite in html. I don't get why people think the former is better.

→ More replies (1)

14

u/third774 Nov 19 '18

With a component architecture, concerns are still able to be separated. It's just less useful to separate along languages lines than it used to be.

7

u/[deleted] Nov 19 '18

Right? I'm seeing this as mostly programmers bored of/against structure and wanting to have "interesting" work, which really means reinventing the wheel.

The few React guys I've known;

  • have invented their own framework on top

  • have told me they want to do "interesting" work

  • forgo any standards and write whatever the fuck comes to their mind

Needless to say while it's worse than any backend framework I've ever used, Angular+Material is still my preferred stack. It constraints developers to a standard, opinionated, way of doing things as much as it can. I've also heard good things about Vue but had no chance to experiment with it.

I also lived through PHP and JQuery spaghetti. Never again.

6

u/vplatt Nov 19 '18

Angular+Material is still my preferred stack. It constraints developers to a standard, opinionated, way of doing things as much as it can.

Amen!

And ng-cli really makes it a pleasure to work with.

→ More replies (2)

10

u/Eirenarch Nov 19 '18

JSX also feels pretty wrong on first glance

That's because it is

13

u/st_huck Nov 19 '18

JSX is wrong, but it's almost a feature by design. It forces you to write small components to keep the JSX under control.

It's like 90% a good thing, but deadlines and migrating legacy code to React do happen in the real world. And when you do end up with a a large-ish component JSX becomes a serious pain.

15

u/jl2352 Nov 19 '18

I kind of agree with you. It is 'wrong', and that's why it's so good.

The old fashioned way of web development (and GUIs in general) was to keep HTML, JS, and CSS, as totally distinct things. CSS Zen Garden being the epitome where entirely different designs are pluggable. In practice this is a waste of time. It's like when people design their SQL to be DB agnostic, and yet only ever run it on Postgres.

You end up with a lot of drift. It's common that people are only ever adding to a CSS file and never removing. I worked on a redesign for a site and we ended up loading both old and new design as about 10% of the old CSS was still used in random places. So users were getting this massive CSS file they just didn't need.

JSX helps to solve these issues. It keeps everything in one place and that way when we remove a component, we remove everything. If I rewrite a component all of the CSS is small and manageable.

Now people may chime in and say you can do it the non-JSX way and keep it manageable. They are right. But it requires a lot of self-discipline. It's a little like saying "just don't write any bugs". It's much better to have a structure that encourages keeping things manageable by design than manageable through self discipline.

6

u/[deleted] Nov 19 '18

100% agree with this. I remember trying to write even small/medium-sized web apps with just HTML, CSS, JS, and some Jquery. If I didn't actively make sure that I meticulously organized my code, it got out of hand in a second. However, with React/React Native projects, having JSX components makes it insanely easy to stay organized. I do agree that large components are hard to handle, but they are way easier to handle than a bunch of disconnected JS files and some HTML where you're never sure what does what. At least a react component keeps logic for one thing in one place.

1

u/[deleted] Nov 19 '18

I'm lost - isn't JSX just a way to transpile html looking code into hyperscript? What does that have to do with CSS?

→ More replies (5)
→ More replies (1)

1

u/[deleted] Nov 19 '18

What's wrong with it?

2

u/st_huck Nov 19 '18

It takes a declarative language (html) and turns it into something that has big parts that aren't declarative. It's has syntax that is just ugly to see in a javascript file, all those {} and <> mixed in there. hacks like 'condition && <div>' are common. And at the end of the day your "logic file" has in the same file a lot of things that aren't logic related.

All those issues are minimized when you write small React components, and overall I prefer it to the alternatives, never wrote otherwise. But looking it plainly from a non-pragmatic perspective, it violates a lot of principles.

6

u/[deleted] Nov 19 '18

Are you suggesting that it's a bad idea to be able to render presentation logic in the same language as your business logic? Or do you just have a problem in inline HTML inside of javascript? I personally hate JS in general, and I don't particularly like JSX either, but I'm definitely not against internal DSLs being used to render views (as opposed to a special templating language).

Separation of view/business logic is really a separate concern in my opinion, but it's good that some templating engines enforce this.

2

u/[deleted] Nov 19 '18

I think this can definitely be true. However, I do think that you can very easily separate business logic from your react components. I think in principle, a react component is about being a function that, given data, deterministically returns a view. If you keep your logic in other libraries/helper files, and use state tools like redux-saga, you can pretty easily separate business logic from views. Of course, there is still some logic in your components, but that is because views often need to have some logic in them. (For example, something like shouldShowSearch: boolean, which conditionally hides or shows a search bar in your component.)

→ More replies (1)

1

u/reddit_ro2 Nov 19 '18

I feel it is a very strong template engine. I usually use Smarty. I like JSX.

→ More replies (13)
→ More replies (6)