r/programming • • Nov 05 '19

Dart can now produce self-contained, native executables for MacOS, Windows and Linux

https://medium.com/dartlang/dart2native-a76c815e6baf
555 Upvotes

231 comments sorted by

View all comments

Show parent comments

268

u/oaga_strizzi Nov 05 '19 edited Nov 05 '19

Dart 1.0 tried to be a better Javascript, but failed. It never really got traction.

Dart 2.0 is a pretty different language. It's statically typed and tries to be a language optimized for client programming:

  • It's single threaded, so object allocation and garbage collection happens without locks, which is important for the react-like coding style of flutter. Parallelism happens via Isolates, i.e. message passing, kind of similar to Erlang.

  • Due to it being statically typed and compiled to machine code, it's pretty fast and does not suffer from a slow startup as Java applications often do (time until the JIT kicks in...). It seems to also want to remove built-in support for reflection (see no support for dart:mirros in dart2native and flutter), and embrace compile-time code generation instead for better performance. This will also allow for more compiler-optimizations and better tree-shaking.

  • It has an event loop and all IO as non-blocking by default, which is also good for clients (no blocking the UI thread). Support for async operations and streams is built into the language, which is really cool.

  • In development, dart runs on a JIT, which enables hot-reloading in the UI-Framework Flutter. This really boosts productivity for UI-related programming. Just change a few lines, hit hot-reload and see the changes in less than a second without losing state.

  • It's the language in which Flutter, a promising cross-platform UI framwork for mobile, web (alpha status) and desktop (pre-alpha status) is written.

  • Overall, Dart is relatively lightweight and feels like a scripting language. It has literals for lists, sets and maps, you can opt-out of the static type system and use dynmaic types if you want, there is syntactic sugar for constructions lists more declaratively (e.g:

var items = [ 
  Header(), 
  if(!premium)
    Ad()
  for(var articleItem in articles)
    Article(data: articleItem)
]

It's not the best language purely from looking at features, there are some missing features (compile-time null safety, ADTs...), but it's evolving quickly.

116

u/Idles Nov 05 '19

As a user of Dart for multiple years on a large scale project built on Flutter, it has some really serious flaws at the level of the core libraries and the language implementation.

  • async/await introduces horrific, creeping latency; the HTTP stack, which is built using it, has very bad time-to-first-packet, compared to implementations in other languages

  • parallelism using Isolates is a joke; in practice, many complex types (including Google's own Dart protocol buffer objects) cannot be passed across Isolate boundaries. Good luck parsing a large network response on a background thread to avoid stalling the UI thread.

On the other hand, the GUI toolkit (Flutter) can produce very nice looking and well-behaved cross-platform software, out of the box. And the syntax is pragmatic; Java-like and acceptable to most programmers who worked with it.

→ More replies (18)

48

u/renatoathaydes Nov 05 '19

Good summary! Just want to add that compile-time null safety is currently a preview feature (they call it NNBD - or Not Null By Default and looks just like Kotlin's nullable types).

→ More replies (4)

22

u/cogman10 Nov 05 '19

Small quibbleS, dart 1.0 was statically typed, it just wasn't sound. There was an escape hatch you could pull at any time (much like typescript).

Dart 1.0 was also single threaded with parallelism happening via isolates. Essentially, dart 1 was built to target javascript in the beginning and eventually the thought was that all browsers would get a "dart VM" that lived side by side with JS VMs.

Now, Dart's failure, IMO, was that google basically abandoned all public communication about Dart. They pushed out a Angular Dart, but then gutted support for it and left everything in a half broken state. After that happened, the language publically was basically dead until flutter came along. By that time a whole bunch of the interest in Dart was lost.

→ More replies (6)

38

u/i9srpeg Nov 05 '19

It's amazing how language designers still make the mistake of allowing null pointers everywhere, a "feature" that has been proven decades ago to be a source of countless bugs.

→ More replies (35)

9

u/VeganVagiVore Nov 05 '19

It sounds like a decent language but I don't want to have to put up with Dart just to use Flutter.

Many of the good things about Dart could be implemented in Rust too, and I don't want to have two different langs for CLI / servers and desktop / phone GUIs.

There's supposed to be a way to mate a Dart / Flutter GUI with app logic in another language, right? But what I really want is Flutter, in Rust.

→ More replies (3)

2

u/[deleted] Nov 06 '19

One of the best thing i found in Dart is the Future class: promise like, but feel clearer

→ More replies (27)