Dart MythBusters

There are some prejudgments about Dart, usually from frontend developers who have never used it or for some reason decided that they don't want to use it at any cost:

  • It's just another abstraction layer like CoffeeScript or TypeScript and will become redundant with ECMAScript 6: Dart is more than this. It's a full-stack, modern, object-oriented, class-based language with its own standalone VM, IDE, debugger, profiler, and everything (see Chapter 1, Getting Started with Dart). It takes the best from many of today's languages. You can watch the keynote from Dart Summit 2015 about future plans with Dart (https://www.youtube.com/watch?v=FiXiI2Atexc).
  • It looks like C or Java; it's unnecessarily complicated to do anything with it: More or less, your code is going to be the same length as vanilla JavaScript plus jQuery. You can see a list of synonyms of Dart and other languages at https://www.dartlang.org/docs/synonyms/.
  • It's not natively supported anywhere and never will: The Google Dart team worked on the integration of the Dart VM right into the Chrome browser. On March 25, 2015, they announced that they're canceling this effort and instead, they'll work on better integration of Dart and JavaScript while improving the dart2js compiler.

    This brought some letdowns from fellow Dartisans, but from a practical point of view, it's probably for the best because even with native Dart support, you would still have to compile your code to JavaScript for other browsers.

    The major problem with Dart is that it's hard to use with existing JavaScript libraries and in real-world applications you'll probably choose between using only Dart or not using Dart at all. This was also one of the reasons why the Angular team didn't choose Dart as their language of choice for Angular 2.0. There's also an experimental compiler in development that is designed to generate readable JavaScript code (https://github.com/dart-lang/dev_compiler).

  • You have to rely on the dart2js compiler: The dart2js compiler is an essential part of the Dart SDK. Dart would never have become popular among developers if the compiler didn't work reliably. For this reason, it's very unlikely that the Dart SDK would come with broken dart2js. However, it's true that if your project uses third-party packages, such as AngularDart, which uses custom transformers, it might produce broken code.
  • It's slow and the compiled code is even slower: In fact, it's the opposite for Dart on Dart VM and dart2js is doing pretty good as well. Dart is continuously benchmarked and you can see the results at https://www.dartlang.org/performance/. However, it's questionable whether these tests represent typical use cases for web apps.
  • The compiled JavaScript code is too large: In Chapter 1, Getting Started with Dart, we saw that the difference between the compressed code of compiled Dart and vanilla JavaScript plus jQuery, is very small (we had 37 KB versus 30 KB).
  • You can't use any existing JavaScript: In this chapter, we've already seen that we can and it's quite simple.
  • Nobody uses it in production: There are actually quiet a few of them: https://www.dartlang.org/community/who-uses-dart.html.

There are obviously situations where using Dart is too complicated, for example, when you're creating a website and all you have to do is a few fade in/out animations, handling click events, or appending some HTML elements. In these situations, it doesn't make sense to use Dart and it's better to stay with JavaScript. The real advantages of Dart come with more structured and complicated apps.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.254.61