DEV Community

Discussion on: 2 Months of Flutter Development

Collapse
 
creativ_bracket profile image
Jermaine

Thanks for getting back to me Paul.

It was designed to be a better Javascript, but the dart VM essentially became another v8 VM. An event driven, single process, garbage collected VM.

One of the reasons Dart went ahead was to address JavaScript's short-comings, effectively presenting another option for web development. It was also to help developers be productive by offering an SDK containing a language, set of libraries, tooling and a repository of packages. In other words, it was not just designed to be a better JS.

The ability to compile Dart to Javascript makes sure the VMs stay very close functionality wise. And the type system wasn't fully tacked on until v2.0 of Dart if I got the history correct.

The ability to compile Dart to JavaScript is provided by a separate executable named dart2js, and not the actual dart VM executable. So its pretty flexible what's possible with the dart VM. For example, Dart compiles ahead-of-time to machine code, a functionality JS hasn't got.

The type system was "fully tacked" since day 1. I remember there were initially 2 modes, the main difference being that types were optional in one while types were compulsory in the other. As of Dart 2, it's strong mode and therefore types are compulsory.

The first class JSON supports is probably my favorite feature of Javascript. At any point you can create a javascript object and then serialize it to JSON in two lines of code

It's pretty trivial creating an object(or Map) and serializing it in Dart:

import 'dart:convert';

void main() {
  var myObj = {'foo': 'bar'};
  print(json.encode(myObj));
}

Paste and run this on DartPad

In dart you have to build JSON serialization into each object you create. So if you're doing some rapid prototyping and you're not sure of your program structure yet, this becomes a pain.

You build JSON serialization if you wish to serialize that particular object. You do not have to though. It'll be easier to prototype in JavaScript since it is the nature of the language...its dynamic. However it can be a painful experience building enterprise-level applications with it.

Join the Dart Gitter group if you haven't already. We're a friendly bunch :)

Thread Thread
 
as1ndu profile image
Asindu Drileba

Dart compiles ahead-of-time to machine code, a functionality JS hasn't got.

I thought it was only the Flutter framework code that compiled AOT to machine code since it's underlying graphics library is SKIA(written in C++).

I gut (😁 I don't know what am taking about would be glad to hear some clarification) tells me "vanilla" Dart is interpreted as you need the dart VM hence it compiles Just in Time.

Thread Thread
 
creativ_bracket profile image
Jermaine

Flutter's framework code is written in Dart. It's Dart that contains the capability to compile to machine code, which Flutter uses. If running in the VM then sure it does JIT, in some scenarios with VM snapshots.

Thread Thread
 
as1ndu profile image
Asindu Drileba • Edited

I think it's important to point out that there is a difference between "Flutter"(DartVM + Skia) & "Dart"(just the DartVM)

While it's true that Flutter's high level API is in pure Dart, the underlying engine is not.

Flutter's engine is powered by Skia written in C++.

Skia does the heavy lifting when it comes to painting the UI to screen. C++ for the graphics is why I suspect Flutter can compile to AOT

Vanilla Dart cannot be compiled AOT i.e to machine code it needs a VM

EDIT: It seems AOT compilation has been available for vanilla Dart since version 1.24.

It's just that no one really knows how to use the feature besides the Flutter core devsπŸ˜…

Thread Thread
 
creativ_bracket profile image
Jermaine

Cool, thanks for pointing out the difference. I am aware that Skia is what is being used to draw the graphics on the screen. Presently AOT is exposed for Flutter and hopefully in future will be available on other platforms.

Thread Thread
 
creativ_bracket profile image
Jermaine

Dart now has instructions for AOT dart.dev/platforms#optimized-produ... :)