神刀安全网

Choosing a JavaScript Framework

Choosing a JavaScript Framework

Thanks to Pavneet Singh Saund for telling me about Rob Eisenberg’s recent NDC Osl o talk

Choosing a JavaScript Framework: A look at 6 popular options

I have recently started assessing this myself . It is not an easy decision because there is so much to consider.

Rob Eisenberg is a JavaScript framework expert. He is the main man behind Caliburn.Micro , Durandal and Aurelia , and has also worked on the Angular 2.0 and Angular Material teams. So his advice is well worth a listen, and a watch.

If you don’t have a spare hour to watch the whole talk yourself, I’ve written a summary of it for you with commentary.

Rob introduces himself and says due to time constraints he’ll be presenting a “hello world” like example of each framework. Each app is a web component which simply shows First Name, Last Name and a computed Full Name.

First he asks you to bare in mind that:

  • He’s obviously biased, especially against Angular 2 (also bare in mind that this summary could potentially contain some other bias)
  • Don’t be swayed or swept up by hype. Be professional and choose what meets the needs of your business.

As bias is a theme here, it is only fair to discuss any possible biases I might have.

My brother is a React JS developer. I am also a guest blogger on Outlier Developer , which is run by the same guy behind React JS Consultancy . I do not currently use React JS or any of the other featured frameworks professionally.

I currently use only jQuery , Bootstrap , and a few small libraries, which in my opinion is all you need for small projects. However I am currently working on a big project, so I need to get agreement on a suitable framework quite soon.

I am not paid to write for Outlier Developer or have any financial interests in any particular framework.

Any personal commentary on the talk is (italicized and in round brackets) .

Rob believes our tendency to jump to technology choices too quickly is a systemic problem in our industry.

The frameworks under the spotlight are:

Rob says he’s trying to be as unbiased as he can be, and will cover the frameworks in alphabetical order.

He points out that they aren’t all frameworks in the same category, or even all frameworks.

Angular 1.x is an all-in-one framework. Rob says it is

pretty much deprecated, there’s literally a fixed number of months left on the lifetime of that framework

and

it’s probably fair to say that you shouldn’t start a new project in Angular JS right now, and you should be thinking about how you might migrate any existing code bases.

(I’ve never been much of an Angular 1.x fan, but I feel it is only fair to point out that Angular 1.x is currently actively supported, and every framework has a number of months left in its lifetime, whatever that means.

If you are interested in using the Ionic Framework then you need to adopt Angular 1.x as well. To dismiss Angular 1.x is also to dismiss the Ionic Framework. Ionic v2 will use Angular 2 but it is currently quite far away from RTM. Rob doesn’t mention mobile at all in the talk.)

Rob describes Angular 2, Aurelia, Ember and Polymer as also All-in-one frameworks, but modern ones.

React is not a framework, per se. It’s a view rendering engine or a component model.

Rob says that although the demo is extremely simple, it shows the different approaches that each framework takes.

Rob recommends Visual Studio Code and is using it on his Mac.

(For brevity, I’ll be referring to lines of code. Some lines of code can be much longer or shorter or more or less readable than others so to get the full picture you’ll need to watch the video for yourself. Rob has a style of leaving a blank line at the end of each file. I will discount those.)

Angular 1.x

index.html is 13 lines of code

We see the ng-controller and ng-model directives.

app.js is 8 lines of code. Rob describes this as a throwback to the previous generation of frameworks: Angular specific modules rather than ES2015 modules. He describes the Angular 1 two way data-binding model.

Angular 2

Rob says Angular 2 really focuses on TypeScript , and

it is much more difficult to use plain JavaScript so most people are going to be kind of pushed down the TypeScript road necessarily with Angular 2

(The equivalent documentation is available for TypeScript , JavaScript and Dart . Judge for yourself how much more difficult it is to use with plain JavaScript)

index.html is 32 lines of code

(I find this is disrespectful to the intelligence of Javascript developers, as if we are mere code monkeys who cannot think. I believe that Rob is smart enough to write better Angular 2 implementation than this. Rob has found some Angular 2 documentation that pulls in a whole load of modules. For the purposes of developing a hello world type app, Rob is pulling in the following modules:

There is also a bunch of code for here configuring a System JS module loader. System JS is written by Guy Bedford and Max Norlund and has nothing to do with Angular 2

Update : I have found this code is very similar to the Bill Stavroulakis “Hello Component” demo which you can find on Plnkr . Bill describes it as “a very simple Angular 2 setup”. I was very surprised to find that this simple demo won’t work at all without Rx.js. You can create “Angular 2 components” easily, but using the Web Components standard with Angular 2 appears to be a lot harder.

Bill is a fan of Polymer JS and has created Hello Component demos for the following frameworks:

main.ts — 4 lines

app.component.ts — 20 lines

Rob explains the Angular2 decorator. He uses an inline template rather than using a template URL. He also explains two-way data-binding in Angular2, and points out that Google have deviated from the HTML specification by using mixed casing.

Aurelia

index.html — 10 lines. This imports System JS and uses it to import the Aurelia bootstrapper.

app.js — 8 lines

app.html — a template with 5 lines of code. Rob explains the two way data binding mechanism used here.

Ember

index.html — 16 lines. Imports jquery, handlebars, ember and app.js

app.js — 23 lines. Rob says Ember is a very strict MVC paradigm and requires a router even for Hello World.

Polymer

index.html — 10 lines.

my-app.html — 22 lines including template, a script block and 4 blank lines.

Rob says the web components centric philosophy concerns him because

…it doesn’t make sense to do everything in HTML but there it is, that’s my opinion

(Rob could have easily put the JavaScript in a JavaScript file. Polymer doesn’t stop you from using JavaScript at all, it just provides some short-hands that can reduce the amount of JavaScript that you need to write.)

Rob likens Polymer to the long forgotten Microsoft Acropolis project from 2008 which tried to do everything in XAML.

React

index.html — 13 lines, importing es5-shim , es5-sham and console-polyfill

(Again, some totally unnecessary imports doing nothing except adding ridiculous complexity to a hello world app.)

app.js — 39 lines.

At 28 mins in we’re wrapped up with the hello world examples and go into the slides.

Technical

Size (minified, not gzipped)

  • React+Redux — 156k or 167k with plugins
  • Angular 1 – 158k minimum, 240k with router, HTTP and animation system
  • Polymer — 222k minimum, 302k (spec compliant)
  • Aurelia — 252k minimum, 302k with standard plugin
  • Ember — 435k including router
  • Angular 2 — 698k minimum, 919k with RxJS, 1023k with RxJS and router and HTTP client

Rob mentions that the Angular team are usingtree shaking to reduce the file size.

Repaint Performance

This test uses DB Monster Repaint. Numbers are frames per second.

Aurelia— 90–105/130–150 (with optimisation plugins)

Angular 2— 80–90/110–130 (with optimisation plugins)

Polymer— 50–60

Angular 1–50–55

React— 45–50

Ember— ???

Rob says that to be honest all of these frameworks are very fast because 50 frames per second is faster than what we can usually see.

(This tool was popularised by Ryan Florence (from Facebook) in his talk at Conf 2015 showing React was faster than Angular 1 and much faster than Ember at the time it was recorded.

You can see Matthieu Ancelin’s dbmon repaint rate challenge which tests a much wider choice of frameworks, however Aurelia is a “TODO” implementation at the moment.

I ran the optimised tests Rob’s selected frameworks on my laptop on Chrome 51 for Windows and got these results:

Angular

–36 to 38 fps

React

— 39 to 43 fps

Angular 2 — 40 to 70 fps

Only naive implementations for Polymer 1.4 and Ember are currently available

Polymer

— 43 to 50 fps

Ember — 1 to 2 fps

I also ran these tests on Edge and found Angular 1 outperformed Polymer on there. Ember performs terribly on Edge at less than 1 fps.

Many other fast frameworks are tested here as well. Angular Light and Motorcycle score well. At the end of the talk Rob recommends Riot as an alternative to React. I found Riot only scored about 10 fps. Also see more benchmarks from auth0)

Standards Compliance

Aurelia: HTML, ES 2016, Web Components (including the Shadow DOM)

Polymer: HTML, ES 2015, Web Components

Ember: HTML, ES 2015

Angular 2: ES 2016 (TypeScript). Non Compliant: NG2 Markup and Dart

Angular 1: HTML, ES5. Non Compliant: Modules, Dependency Injection

React: ES 2015. Non Compliant: JSX

(Web Components is not yet a standard.

Web Components Shadow DOM is currently a

Working Draft Web Components Custom Elements is a Working Draft

TypeScript is not a standard, and ES 2016 is a standard.)

Separated Presentation

Excellent: Aurelia and Ember

Moderate: Angular 1

Poor: Angular 2 and Polymer

N/A: React

Rob says Separated Presentation is less of a technical issue than a people issue.

Obtrusiveness

Unobtrusive: Aurelia

Average: Ember

Obtrusive: Angular 1, Angular 2, React

Rob provides some commentary for the purpose of justifying these claims.

(These are opinions not measurements)

Interoperability

Very Interoperable: Aurelia, Ember, Polymer

Average: Angular 2

High Friction: Angular 1, React

That concludes the technical comparison. At 43 minutes in Rob moves on to discussing the project and the team.

Project and Team

The table is very useful but has too much information to recreate here, so see the video at (43:30) for that.

Rob says although Angular 2 is claimed to be at Release Candidate Status, there are still breaking changes being made and

it’s not really a release candidate if you look at what’s really happening there.

Rob says there is a patent clause in the React license, which prohibits you from using it to compete with Facebook, or if you have an intellectual property dispute with another company using React.

He says this is why Google and Microsoft employees don’t use React.

(You can find React’s Patent clause here )

Core Team

Another detailed table at 48 mins in. Rob claims that the Angular teams don’t use their own frameworks, and that only the Aurelia and Ember teams are available to provide training.

(If you need React JS Training it is provided by Ryan Florence and Michael Jackson from Facebook)

Community and Communication

Another table of information and commentary on how strong each community is and how well the teams communicate with those communities.

Learning Materials

All frameworks score well on this.

Business

Another table of information at 54 mins giving details on:

  • Corporate Buy-in
  • Commercial Support
  • Consulting
  • Customer Relations
  • Official Relations
  • Official Partners
  • Motivation
  • Brand Recognition

Rob says Angular 1, Angular 2 and Polymer are not Google products. They are open source side projects from teams inside of Google.

(For detail’s on Google’s CRM system greentea, and it’s relationship with Angular, see How Google Uses Angular 2 with Dart . Google has also rewritten Google Adwords using Angular 2, and this is millions of lines of code.)

Recommendations

Yes: Aurelia and Ember

Maybe: Polymer (or web components JS) and React (or Riot to avoid the patent problem and smaller size)

Rob says React is much better for read only apps and a lot more work for input intensive apps.

No: Angular 1 and Angular 2

Rob finishes the talk by re-iterating that he is biased, but hoping that the talk included useful information.

(I definitely feel that this talk has been useful to me and there were a number of good points that I will bare in mind during my assessment. When doing your own assessment don’t forget there’s also Meteor, Cycle, Marionette, Sails and many others worth considering.)

Agree with Rob’s opinions? Disagree? Please leave your comments to discuss.

Further Reading

Choosing a JavaScript Framework — Rob Eisenberg at NDC Oslo 2016

Rob Eisenberg on Aurelia and how it stacks up against Angular 2 and React

Todo MVC examples in many, many frameworks

Front End Masters: Brian Holt’s JavaScript Framework Showdown (Angular 1/Ember/Backbone/React)

React.js Conf 2015 — The complementarity of React and Web Components by Andrew Rota

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Choosing a JavaScript Framework

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址