When comparing Dart vs GHCJS, the Slant community recommends GHCJS for most people. In the question“What are the best solutions to "The JavaScript Problem"?” GHCJS is ranked 8th while Dart is ranked 10th. The most important reason people chose GHCJS is:
With a Haskell backend, GHCJS enables code sharing. In combination with the power of Haskell as a language, this enables an extremely tight integration of the client side with the server side, where all the communications take place in a type-safe manner and even transparently if desired.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Great async language support
Dart is a single threaded programming language. So if any piece of code blocks the execution of the program, the program practically freezes. To avoid this Dart makes use of asynchronous operations which let your program run without getting blocked. This is done through Future objects.
A Future is an object which represent a means for getting a value at a certain point in the future. A function may invoke a Future and when that happens, two outcomes can be achieved:
- The function is unable to return a value, so it queues up work to be done and returns an uncompleted Future object.
- Or later when a value is available to be returned, the Future object completes with that value.
Pro Great standard library
Dart includes a truly comprehensive core library, making it unnecessary to include disparate, external resources for basic functionalities Other than reducing the need to pull in various 3rd-party utilities this also ensures that all Dart code looks and feels the same.
Out of the box, the developer gets core libraries to help with: async, collections, strings, regexps, conversions, formats, file I/O, math, typed data, and more.
Pro No compile time in development
Dartium (Chromium derivative) is a browser with integrated Dart VM, which allows you to run and debug native Dart code during development for short edit-reload cycles. Only for testing on other browsers and deployment is transpiling to JS necessary.
Pro A lot of tools are available to help in developing with Dart
Dart has a lot of tools available which help with developing Dart applications. Some examples of those tools include:
- pub - package and dependency management and build tool
- analyzer - static syntax analysis with linter, quick fixes, autocompletion support for easy IDE integration
- test - powerful and flexible testing framework and test runner
- dev_compiler - generate reusable JS instead of tree-shaken minified JS output (work in progress)
- dartfmt_ - source code formatter
- server-side VM
- observatory - a powerful tool for profiling and debugging running Dart code (for Dartium and Dart server code)
Pro Transpiled JavaScript code works on all browsers
In Dart many browser differences (subtle differences and also missing features) are abstracted away or polyfilled. When Dart is transpiled to JS the output works on all supported browsers. There is usually no need to load polyfills or to consider browser differences during development. No need for libraries like jQuery to make the same code work the same on all browsers.
Pro Will be familiar to Java developers
The language will look familiar to Java developers, easing the learning curve.
And yet, while it's similar, it has some nice syntax facilities to avoid common boilerplate code found in Java. Code is terser, yet readable.
Pro Easy prototyping
Dart has an optional type system which makes Dart a great language for prototyping. It encourages developers to gradually evolve their programs without worrying about types first.
Pro Can compile to efficient machine code
Dart was designed to be as expressive as possible. Ahead-of-time compilers can compile Dart code to efficient machine code. This is especially important when deploying to mobile where you don't want (or can't) use a JIT.
Pro AngularDart 2.0 support
Pro Optional strong mode.
Strong mode applies a more restrictive type system to Dart to address its unsound, surprising behavior in certain cases.
Pro Support of semi-coroutines (generators)
Generators, also known as semicoroutines, are also a generalization of subroutines.
Generators are primarily used to simplify the control of iteration behavior of a loop, the yield
statement in a generator passes a value back to a parent routine.
A generator is very similar to a function that returns an array, in that a generator has a certain number of values. But instead of building and returning an array that contains all the wanted values, a generator returns them one at a time, this saves memory and allows the caller function to start processing the first few values immediately.
Pro The Dart to JavaScript compiler generates high quality source code
Dart to Javascript compiler (dart2js) generates very high quality source code with very high optimization. The output code is also very readable and easy to understand.
Pro Crossplatform
Dart does not just compile to JavaScript, it also compiles to native code on mobile platforms like iOS and Android as demonstrated by flutter.io
Pro Full Stack Code Sharing
With a Haskell backend, GHCJS enables code sharing. In combination with the power of Haskell as a language, this enables an extremely tight integration of the client side with the server side, where all the communications take place in a type-safe manner and even transparently if desired.
Pro All of Haskell, with the same tools you're used to
No need to learn new syntax or semantics, and no need to install and learn a bunch of new tools - it's just GHC.
Pro Mature language and community
Pro Terse
Haskell is a very terse language, particularly due to its type inference. This means there's nothing to distract from the intent of the code, making it very readable. This is in sharp contrast to languages like Java, where skimming code requires learning which details can be ignored. Haskell's terseness also lends itself to very clear inline examples in textbooks, and makes it a pleasure to read through code even on a cellphone screen.
Pro Quick Feedback
It's often said that, in Haskell, if it compiles, it works. This short feedback loop can speed up learning process, by making it clear exactly when and where mistakes are made.
Cons
Con Doesn’t generate consumable JavaScript at present
Dart builds to JavaScript but the entire app needs to be built to JavaScript at once for now (that may change in the future).
Con Still many holes to fill while converting code to Javascript
While implementing callbacks, passing a type to any function that gets passed to Javascript causes the dart2js compiler to crash.
Con Dart SDK does not provide standard (out of the box) way to access SQL-based databases on server side
This missing (but very popular) feature requires to use 3rd-party packages developed by the personal enthusiasts or very small groups of enthusiasts, which is not very convenient because they are all very fragmented in terms of content, the essence and capabilities.
Con Small community, little momentum
Con May be difficult to use some JavaScript libraries
Dart is much more than a programming language, it's a platform with its own standard libraries and tools. It's a major departure from JavaScript itself (even though it can compile to JS) that it's not possible to directly interact with JavaScript libraries in Dart. Instead, you have to use a special interop library which exposes the wrapped versions of the JavaScript objects that you are accessing.
While this enables Dart to sandbox JavaScript so that its problems do not leak into a Dart application, it also means that it may be cumbersome to use libraries which don't have a wrapper library available.
Con Large runtime
GHCJS supports the entire Haskell runtime, the Javascript it outputs tends to be quite large. This is in contrast to options such as Fay, which save some overhead by not supporting some features such as multi-threading.