News for hackers. Stuff that matters.
Re:The Brutal Lifecycle of JavaScript Frameworks by codingdave on Thursday January 11, 2018 @09:53AM (#16124181)
On the same note, the older frameworks solved older problems. jQuery was the killer framework because it handled browser compatibility back in a time when people not only needed to support IE8, but IE6, and few companies felt comfortable telling people to just update their browser. Well, those days are past, so that problem is no longer a reason to choose a framework, and when you take that out of the picture, jQuery just isn't so needed.

The same path is likely on all frameworks - they were designed to solve specific use cases, and as the entire industry matures, different solutions will embed themselves in the industry in different ways, reducing the raison d'etre for each framework, over time.

Re:The Brutal Lifecycle of JavaScript Frameworks by shams93 on Thursday January 11, 2018 @10:47AM (#16124776)
Yeah with jquery we were composing templates server side. Compared to Vue trying to do a SPA in jQuery is a season in hell. It can be done but it's brutal and fragile.
Re:The Brutal Lifecycle of JavaScript Frameworks by eitland on Thursday January 11, 2018 @11:57AM (#16125415)
> It can be done but it's brutal and fragile.

Actually many who did jQuery were proud of it.

Some of us made rock solid sites or improved exiting ones quite a bit using a technology known as progressive enhancement.

Let me tell you what is fragile: the cool things I make today that won't even try to work if I disable Javascript. :-)

Edit: and given what we have seen over the last few days now would be a good time to reconsider if every website really needs to be able to run Javascript.

Re:The Brutal Lifecycle of JavaScript Frameworks by djroomba on Thursday January 11, 2018 @01:23PM (#16126304)
I miss progressive enhancement, when/why did it die.
Re:The Brutal Lifecycle of JavaScript Frameworks by bronson on Thursday January 11, 2018 @02:01PM (#16126682)
Did progressive enhancement ever catch on? It made for some great Rails 2 tutorials but I don't remember seeing it much in the wild.

It's going away because you basically have to write everything twice and it's hell to keep consistent.

Re:The Brutal Lifecycle of JavaScript Frameworks by Can_Not on Friday January 12, 2018 @08:04AM (#16132493)
If you need your website to work without JS, Nuxtjs is an amazing VueJS framework for SSR or static prerendering.
Re:The Brutal Lifecycle of JavaScript Frameworks by pascalxus on Thursday January 11, 2018 @12:25PM (#16125701)
I'm quite surprised at this conclusion. I've always felt that doing SPA with jQuery was the easiest thing I've ever done in my development career. It's so easy to get something set up and running. And it's a breeze to figure out and read the code too: even when it's 10s of thousands of lines of code.

Is it just me, or are many of the newer frameworks actually harder to use? I tried Angular 1 about 4 or 5 years ago and it seemed like a complete disaster. Recently, I've been working on Vue and this seems a bit better.

Re:The Brutal Lifecycle of JavaScript Frameworks by bronson on Thursday January 11, 2018 @01:51PM (#16126600)
Depends on the SPA. If you're trying to do something relatively simple, where the events and state clearly map to the UI, jQuery isn't too bad. It's even fun.

Once your SPA goes through an iteration or two with a few different programmers, you find your events have nasty ordering dependencies and your data becomes inconsistent all on its own. You have no idea why because you can't reproduce any of these issues on your own. You have to watch other people interact with your app just to reproduce bugs ("why the hell would you double click a link?") and git bisect becomes the most productive tool in your toolbox. Most project discussions end with a shrug. You yearn for the days when it was possible for a single human to ever understand the entire app, but that was six months ago and management steadfastly refuses to fund a rewrite. You look wildly around for any sign of hope...

As for Angular, agreed, but I'd rather work with it than a bunch of jQuery. React and Vue are quite pleasant.

Re:The Brutal Lifecycle of JavaScript Frameworks by Albert_Camus on Thursday January 11, 2018 @03:25PM (#16127485)
>And it's a breeze to figure out and read the code too: even when it's 10s of thousands of lines of code.

Not at all. The issue with an application written in jQuery is a lack of sane state management. Forgetting to initialize (or re-initialize) values, not expecting things to be executed in a different order, and just poor organization in general led to mountains of runtime errors.

Nowadays we use Elm. The difference is night and day. I wrote a post on this topic a few months ago: https://charukiewi.cz/posts/elm/

Re:The Brutal Lifecycle of JavaScript Frameworks by always_good on Thursday January 11, 2018 @01:40PM (#16126491)
> And [jQuery is] a breeze to figure out and read the code too: even when it's 10s of thousands of lines of code.

> Is it just me

Probably.

Re:The Brutal Lifecycle of JavaScript Frameworks by pjmlp on Thursday January 11, 2018 @12:10PM (#16125542)
For the majority of my web development that verb is in the present tense.
Re:The Brutal Lifecycle of JavaScript Frameworks by lolive on Thursday January 11, 2018 @12:26PM (#16125716)
I am not at all a front-end developper. But isn't jQuery the DOM API done right? [Which is a good thing, but only the beginning of the journey.]
Re:The Brutal Lifecycle of JavaScript Frameworks by sim0n on Thursday January 11, 2018 @04:47PM (#16128245)
DOM APIs have much improved since jQuery first arrived, so while that was the case originally, it's become less true over time. It's definitely still less verbose though, for example:

  $('.my-component div').css({ background: 'yellow' })
vs.

  Array.from(document.querySelectorAll('.my-component div')).map(node => {
    node.style.background = 'yellow';
  })
Re:The Brutal Lifecycle of JavaScript Frameworks by esprehn on Friday January 12, 2018 @12:42AM (#16130656)
The modern DOM API has forEach on NodeList so you can skip the Array.from.

  document.querySelectorAll('.my-component div').forEach(node => node.style.background = 'yellow');
https://developer.mozilla.org/en-US/docs/Web/API/NodeList/fo...
Re:The Brutal Lifecycle of JavaScript Frameworks by scottmf on Thursday January 11, 2018 @06:01PM (#16128873)
Why use map instead of forEach?
Re:The Brutal Lifecycle of JavaScript Frameworks by tvalentius on Thursday January 11, 2018 @08:27PM (#16129701)
If you only want to translate(map) each element in to another set of value, using Map is much more simpler and readable than forEach
Re:The Brutal Lifecycle of JavaScript Frameworks by grumblestumble on Friday January 12, 2018 @01:27PM (#16135065)
Actually, this is incorrect. You're abusing map here. The purpose of map is to map an existing array onto a new array. You're using map here to mutate properties on nodes in the original array, and creating a new Array, which has the length of the initial array, where each value is the return value of `node.style.background = 'yellow';`

forEach is much more indicative of what you're actually doing here, which is running through an iterable and mutating properties on each node.

Simple rule of thumb: if you're not using the results of `map`, you shouldn't be using it.

Re:The Brutal Lifecycle of JavaScript Frameworks by scottmf on Friday January 12, 2018 @10:59AM (#16133817)
The code loops through an array, has side effects and returns nothing so forEach would be more descriptive IMO.

As for simple/readable it’s the same code but s/map/forEach.

Re:The Brutal Lifecycle of JavaScript Frameworks by dandelany on Thursday January 11, 2018 @12:45PM (#16125899)
Yes, in a way... it’s certainly (IMO) nicer to use than the DOM API. But “done right” used to mean not just “nicer to use” but “actually implemented correctly” (unlike major browsers at the time). Now that the DOM basics are pretty well-standardized, it’s mostly just “sugar” which isn’t necessarily worth the extra bundle size.

Another, bigger factor is that most modern frameworks use some form of templating and binding which means that you have less need to modify/interact with the DOM directly.

Re:The Brutal Lifecycle of JavaScript Frameworks by pjmlp on Thursday January 11, 2018 @12:09PM (#16125527)
I wish those days were past.

Need to target IE 11 and FF ESR currently.