Few things that you are probably getting wrong about why Flutter uses Dart.

More and more often, I would get emails about why people think Google choose Dart for Flutter. It seems, most of those articles written by people who just joined the Flutter crowd and did not follow Dart’s evolution from the very beginning. So, as a person who followed it from pretty much day one, I decided to write a few lines about why, do I think, Google preferred to use Dart to any other alternatives.

1. Dart was designed for the UI development and that is why it was chosen for Flutter.

WRONG. Dart was developed as an alternative to JavaScript to run in the Browser, and thus, the main goals were:

  1. To be able to compile it as fast as possible: When the browser loads the page, it cannot perform any scripted actions until the JavaScript (or in our case Dart) is fully loaded and interpreted/compiled. And for huge enterprise applications, it is especially critical. So, the Dart, besides JavaScript, is the only language that was designed with that goal in mind. This is what allows Flutter to have its superior “Hot reloading” feature.
  2. To be as performant as JavaScript: Back then, JavaScript was already fast enough so there was no critical goal to make it faster, though it is something that is always welcome. In fact, the very first version of Dart was dynamically typed and types, as we know them from languages like C, were optional only needed for code readability and IDE’s assistance. Developers did not have to use them and even if they would, those types will be checked at runtime anyway.
  3. Dart was inspired by OOP languages like Java but was designed to be easily adopted by the Web development community which back then used mostly JavaScript and CoffeeScript to some extend. The importatnt goal was to make it friendly for those developers and there was nothing in Dart which could be considered UI-specific.
  4. All those features like “new” operator removal or conditions in arrays, were added after Flutter was introduced. Those were added to address pure readability of the Flutter widgets code. Let’s be honest, XML and derivatives like HTML or JSX are the only “languages” which was designed for the UI.

2. Dart was chosed over JavaScript because of the AOT.

WRONG: In a very first place, Dart did not have AOT and it was added specifically for the Flutter and NOT because the AOT is faster. In fact for quite some time AOT compiled Dart code was quite a bit slower than its JIT version. The reason why is because Google already had highly optimized VM for browsers. Reasons, why Google choose Dart and added AOT are:

  1. AOT is the only option on iOS platforms because Apple prevents any other JIT-optimized languages except JavaScript which you can run only on Apple’s VM.
  2. AOT compiled applications much faster to launch (To launch! Not to run!) because the compiled code can be executed right away without the need to compile and optimize it.
  3. AOT execution is more predictable. Flutter was designed to build highly interactive applications with a lot of animations running at 60 fps. Some JIT implementations like the one for Java or JavaScript can be problematic to deal with. Because JIT compilation and optimization takes time, VM does not try to optimize everything once you launch the app and just runs interpreted version instead and will try to optimize the code which used often. Imagine, if you have a Material button with a ripple effect. Once you click that button, the ripple effect will not be optimized yet and will not be efficient for some amount of frames. Then, VM might try to optimize the code while the ripple effect is still running and the user will see some lags. The button is a very simple example but in the context of the entire application, it is much simpler to deal with predictable AOT execution.
  4. Google could add AOT compilation for JavaScript but due to its dynamic nature it will be much harder optimizing it.
  5. JavaScript is a standardized language so, google will not be able to add any syntax changes or improvements to their implementation otherwise it would not be JavaScript anymore. And if you make your own language with your own compiler, why would you base of JavaScript?

3. AOT is faster than JIT.

WRONG: AOT compiled code does not assume superior execution performance. Superior launch speed? Yes — you do not have to compile it first. Less memory needed? Likely, Yes — you do not have to keep VM in memory. But not execution speed. In fact, JIT, theoretically, can be even faster, because compilation would happen on the target hardware and VM can make some optimizations specifically for the environment where the user is launching it.
For example, both Java and C# code will perform better than AOT-compiled Dart code most of the time.

4. Google should’ve to use Kotlin, Go, or any other language for the Flutter.

When Google started to work on Flutter, there was no real alternative to it at that time. Kotlin was not a thing yet. Java and other platforms will not be able to provide a “Hot reloading” feature. But more importantly, Google does not own those languages, thus, would not be able to evolve any of those the way they want. So, there is no point comparing Dart with any other language in the context of Flutter. You are not complaining to Apple that they use Swift but not Java. They just build tools that make the most sense for their platforms.

Conclusion

There are other reasons why would Google decided to use Dart. For example, Google invested quite a bit of resources building Dart and tooling for it. According to them, even before Flutter, Dart was in the top five languages list used at Google which already could be a justifiable reason, but those I listed, I think are the most important from the technology perspective.

It would be so great to get the feedback from original Flutter creator, because those one above are just my speculations and I will be happy to confirm ore dispel them.

As always, great thanks for reading!!!

Passionate Software Developer with a strong focus on Web, 3D, Mobile, and pretty much any interactive computer graphics.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store