Flutter 1.0 released
With the recent release of Flutter 1.0, Google released another platform to develop mobile apps. The focus of Flutter is to develop cross-platform applications. This allows developers to develop their application only once and publish it on multiple platforms, such as iOS, Android, Web, and even native desktop applications.
The Flutter platform is powered by Google’s own programming language, Dart. Google, not a stranger to creating their own languages (Go is another example), choose not to use a more widely used language out there, such as TypeScript, but instead use their own language.
What is Dart?
Dart is a programming language originally developed by Google. The language is designed by Lars Bak, who, before working for Google, worked on multiple Virtual Machines, such as the JVM, and a VM for Smalltalk. At Google, besides working on Dart, Lars also worked on the V8 Javascript engine.
Dart itself is an object-oriented programming language inspired by Java, Javascript, Smalltalk and Erlang. While it’s originally launched in 2011, the adoption of Dart hasn’t been great. Not many projects have been written in Dart, and only several books have been published in the last 5 years. Only since 2017, with the introduction of Flutter, does Google show again a bit of interest in the language.
While the development team behind Flutter and Dart claim the Adsense interface has been written in Dart, which should indicate a sense of maturity, it’s helpful to note that this also the only (medium-sized, 160K Lines) project written in Dart by Google, and that the earlier version of Adsense has been written in GWT, which has since died a silent death.
What’s the popularity of Dart?
According to the Tiobe Index of January 2019, Dart ranks higher than Kotlin and TypeScript. The Stackoverflow Survey of 2018, Github’s State of the Octoverse (2018) and also my own experiences show very different results. As a result, I don’t have great confidence in Tiobe in this case.
Another resource, CodeMentor, ranks Dart as the Worst Programming Language to Learn in 2018 in terms of, well, all criteria really. So, we’re off to a not so great start. So, why would one even consider learning Dart? Good question!
However, since there are a few languages existing like Dart, one cannot help but ask if running Flutter on Dart was the best thing to do, in terms of features, as well as developer experience.
In this post, we’re going to have a look at some competing languages, their maturity and capabilities. We’ll see how to they compare to Dart, so as to understand better why the need for a new programming language was deemed necessary by Google, instead of leveraging the capabilities of existing languages such as TypeScript or Kotlin.js.
I’ve chosen the comparison between Dart, TypeScript and Kotlin.js since all of these languages are Object Oriented, Class based and Garbage collected languages, with similar syntaxes.
What is TypeScript?
TypeScript is a language developed by Microsoft. It’s designed as a superset of Javascript (meaning all Javascript code is also valid TypeScript code), and, as the name implies, TypeScript adds types to Javascript. This makes TypeScript a better language to develop larger applications in, since it gives more compile time safety and prevents errors.
The development of TypeScript has received involvement from Anders Hejlsberg, who is the lead architect for C# and creator of Delphi and Turbo Pascal, and it’s currently maintained by the team at Microsoft, who launch a new feature release approximately every 2 months.
TypeScript, like Dart, has been inspired by a lot of other mainstream programming languages such as Java, C# and Javascript, and the syntax of TypeScript has great similarities with those languages. TypeScript is widely used these days, and is the default language for Angular, Nest (a NodeJS framework), Grafana and many more. Frameworks like Vue.js and React have great support for it. Also, Microsoft’s own VS Code IDE is written in TypeScript.
All in all, TypeScript is a quite popular language with functional aspects, (non-nullable) types, and has an active community.
What is Kotlin.js?
Kotlin is a statically typed programming language designed by Jetbrains, the company behind the well known IntelliJ IDE (and variations thereof). Kotlin runs on the JVM, it compiles to native code (Kotlin Native), and runs in the browser (Kotlin.js) as well.
The Lead Language Designer of Kotlin is Andrey Breslav, who joined JetBrains in 2010 to develop the Kotlin programming language.
The Kotlin language and frameworks evolve at quite a steady pace. Experimental features are added in most releases of the language (enabled by setting a feature flag), and these features are then ported to the other platforms Kotlin runs on, if applicable. While the language itself is quite well evolved, the documentation is not. There is almost no documentation specifically for Kotlin.js. Although there is one example project at the time of this writing, there are virtually no books on Kotlin.js. So, while the Kotlin language (especially on the JVM) works well and is well documented, for the Javascript version of Kotlin there is a little less love at the moment.
Dart vs TypeScript?
Dart and TypeScript are, in principle, languages which look quite similar. When proficient with either Dart or TypeScript, the other language should be quite readable and not hold many surprises.
The bigger difference between Dart and TypeScript is the adoption. While Dart is only adopted by Flutter, TypeScript has a wider adoption. While both languages had their 1.0 release around 2013-2014, Microsoft has been much more successful in pushing TypeScript as a better JavaScript than Google has.
See the below table for a much more detailed comparison between Dart vs TypeScript.
Dart vs Kotlin.js?
As mentioned before, the syntax of all the languages mentioned here are quite similar, and as such, there is not a huge difference between Dart vs Kotlin in terms of readability.
There are however a few big differences between Dart and Kotlin.js. For one, the documentation of Dart is, despite a lack of books, surpassing the available documentation on Kotlin.js. There are Codelabs, tutorials and articles available, while the results for Kotlin.js are, well, disappointing. It’s almost impossible to find any resources on Kotlin.js, and the lack of documentation is a serious impediment for greater adoption.
On the language front, Kotlin has most of Dart’s features, with a more modern type system. Non-nullable types are great to work with, variable assignment is immutable by default, and so is the collection system. Besides that, Kotlin has extension functions, if/switch expressions, data classes, and much more, giving Kotlin a much more mature and modern feel than Dart.
Dart vs TypeScript vs Kotlin.js overview
Dart | TypeScript | Kotlin.js | |
Owned by | Microsoft | JetBrains | |
Created by | Lars Bak and Kasper Lund | Anders Hejlsberg | Andrey Breslav |
Original release date | November 2013 | October 1, 2012 | March 2017 |
Current version | 2.14 (8 September 2021) | 4.4 (26 August 2021) | 1.5.30 (24 Aug 2021) |
Type safety | Optional | Optional | Yes, with dynamic support. |
Generics | yes | yes | yes |
Reified generics | yes | No, whole type-system is erased | Yes, through keyword |
Visibility scopes | Public and Private | Public, private, protected | private, protected, internal and public |
Non-null types | yes, since 2.12.0 | yes | yes |
Functions | First class support | First class support | First class support |
Mixins | yes | yes | Through Kotlin delegates |
Data classes | no | Parameter properties | yes |
Extension functions | no | yes | yes |
If expressions | no | no | yes |
String interpolation | yes | yes | yes |
Operator overloading | yes | no | yes |
Supported platforms | Flutter Web Server | Web Server | Web Server |
Inheritance | yes | yes | Yes, but classes are final (non inheritable) by default |
Sealed classes | no | no | yes |
Javascript interop | Through JS interop package | Native, TypeScript Compiles to Javascript | Transpiles to ECMAScript 5.1 |
Online playground | DartPad | Playground | Playground |
Tooling support | Tooling VS Code IntelliJ Android Studio Atom Vim Emacs | Tooling VS Code Webstorm Netbeans Atom Sublime Eclipse Vim Emacs | IntelliJ VS Code |
Build tools | Own build tool | All major Javascript build tools (Browserify, Gulp, Grunt, Webpack, etc) | Maven, Gradle, Command Line, IntelliJ |
Documentation | Dart documentation (Articles, code labs, tutorials, website, books) | TypeScript documentation | None |
Style guide | Dart Style Guide | No official guide | Kotlin Style Guide |
Book | No recent books | TypeScript Deep Dive (Free) Amazon books | None |
Why did Google choose Dart for Flutter?
One of the most important reasons to choose Dart was not because it’s a superior language to either TypeScript or Kotlin. Dart is currently lacking features which make it a great language, and the adoption of Dart will most likely much depend on the adoption of Flutter. Flutter 1.0 has been released in December 2018, so it’s far too early to say anything about the adoption of Flutter and what effect it will have on the popularity of Dart as a language. Most likely it’s depending on the effort Google is willing to put in to promote the language, if Project Fuchsia will be launched in 2019.
So, while the current popularity is not a great reason for Google to choose Dart, there are a few other reasons:
- Dart is a simple language. Yes, it’s missing features, but it’s very easy to get started with it.
- Much like Kotlin, it runs on the web, mobile devices, and through plugins, also on the desktop.
- But most importantly; it’s owned by Google, so Google is in full control over the VM, the language features, and less likely to be sued by Oracle, Microsoft, or any other corporation.
This blog has been peer reviewed by my colleagues which I’d like to thank them for, especially for the numerous contributions by Winston! Much appreciated!
2 Replies
Hey Erik, thanks for the nice article.
Related to kotlin documentation there is a ton of it, and it is quite good:
https://kotlinlang.org/docs/home.html
Also there are kotlin related books: Atomic kotlin & Effective kotlin.
Thanks for the link, but those books, nor documentation, cover KotlinJS. They cover Kotlin (the language), but there’s hardly anything KotlinJS related.