Search posts, tags, users, and pages
What made you choose Dart? Also how has your experience with Kotlin been?
Dart has always intrigued me, how has your experience been? Are you using it for frontend, server or both?
@Rob: Been using it for 3 years, just frontend. The ecosystem on the backend is not as big as with Kotlin / Java, but frontend it's pretty awesome as a JavaScript replacement and the interoperability with regular JavaScript is fairly good, so I'm using it with existing JS frameworks.
If you switch on the Linter, it's pretty much strongly typed, the only thing I miss is the null-safety you get with Kotlin.
I'd say Dart is my second-favorite language very close on the heels of Kotlin, just waiting for KotlinJS to mature a little more, then I'll probably start building some projects in KotlinJS to see if it's worth going 100% Kotlin.
Marcus I've been using Kotlin since early 2016 and Dart for 3 years. I previously built a large system in GWT and although it worked well, it felt like it took 10 times longer to develop than just using plain old JavaScript. The problem with just using JavaScript on a project that is over a million lines in size is that errors creep in easily, when refactoring code, you break stuff easily and then obviously it's much harder to maintain that JavaScript.
At the time, my options were, go with JavaScript and hopefully don't get bogged down by weird issues, go with GWT and miss my deadlines by a long shot since you have to write UI code in Java or try out Dart which at the time, if I remember correctly, was just about to hit version 1 or just hit version 1.
Writing it in Dart gave me the same agility as with JavaScript and almost the type safety I was used to with Java at the time and those million lines of Dart has been sitting in production for several years already with very few issues.
Kotlin's been awesome, started using it since the day it hit version 1.0.0 and about a month later I ditched Java. It's like going from a 486 with 1MB of RAM to a 16 core PC with 128GB of RAM. Coming from a Java background, Kotlin was just amazing, all the good stuff Dart had, plus the null-safety and method extensions. Took a bit of getting used to writing the variable name first and then the type, but I actually prefer it that way. If you haven't tried it, give it a bash!
That is great news. My first heavy language was Java and most of what I know now I pull from that pool. I have been watching Kotlin closely and hope it overruns Java in the development world to be something jobs ask for.
Also, why not TypeScript? Although I would only use TS ^2 since all the version 1 or lesser had all kinds of user friendly issues. I currently use TS every day for my JS development. I would its type system and null checking would be just up your ally, but if not why then Dart over TypeScript?
TypeScript is certainly a huge improvement over JavaScript, but you still have to deal with the nasties that JavaScript brings along whereas Dart is just a fresh approach with none of the pitfalls of writing JavaScript. Since you're compiling TS to JS, you might as well use Dart and compile to JS which is IMO is much more enjoyable to write than TS or JS.
Kotlin actually has a tool called TS2KT which converts TypeScript to KotlinJS Definitions which you can then directly use in your Kotlin code, see: npmjs.com/package/ts2kt
Hoping that more JS libraries starts using TypeScript, this will make it easier to just drop in TS libraries with KotlinJS in the future. As far as I know, the KotlinJS team will be converting these to Kotlin in the future which means KotlinJS will have a huge selection of options available : definitelytyped.org
I guess my next question would be. What are these pitfalls you speak of? I am looking over Dart and don't really see the great advantage of it. I feel like currently there are more pitfalls when using Dart, which also compiles to JS. Also something about not being able to directly use other javascript packages without some other service.
On Dart, I would like to see Dart become a thing, greater than it is currently. After reading over the documentation it looks pretty stout. I like its simple syntax that has meaning to it, easy to read. I hope TS doesn't overshadow it completely.
An extract from the JavaScript specification, this is just one of many such things that irks me.
11.9.3 The Abstract Equality Comparison Algorithm
The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:
If Type(x) is the same as Type(y), then
If Type(x) is Undefined, return true.
If Type(x) is Null, return true.
If Type(x) is Number, then
If x is NaN, return false.
If y is NaN, return false.
If x is the same Number value as y, return true.
If x is +0 and y is −0, return true.
If x is −0 and y is +0, return true.
Return false.
If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return false.
If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false.
Return true if x and y refer to the same object. Otherwise, return false.
If x is null and y is undefined, return true.
If x is undefined and y is null, return true.
If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.
If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
If Type(x) is either String or Number and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).
If Type(x) is Object and Type(y) is either String or Number, return the result of the comparison ToPrimitive(x) == y.
Return false.
In Dart, if x and y are of different types, then x == y is false by default, no complicated rules.
In JavaScript, if you call plus on two values, JavaScript will attempt to mangle one of the values to make the plus work, in Dart, if it doesn't make sense what you're doing, the compiler will simply tell you, oi, you can't add an object to a number, or in the case of string concatenation, it will ask you to explicitly call toString on that object since adding an object to a string doesn't make sense.
As a result, writing bug-free Dart code is much easier than writing bug-free JavaScript.
I agree completely, I've always disliked those JS warts and I turn to TypeScript where I can and I love it. The type analysis is fantastic. Although as you say, it's only a superset of JS and it only masks the ugliness to a degree.
I dabbled with Dart a few years back but nothing serious. I'd be interested to take another look, especially to compare TS/Dart transpiled JS. Although I have little interest in Angular 2, I'm more of an Aurelia guy. :)
Jan Vladimir Mostert Rob that of course is == which you should never use. You should use === where the comparison is validity and type. There is Also Elm which I would put in the same popularity ranking as Dart. Also TS isn't used just with Angular. You can write your Aurelia with TS. Anything JS can be written using TS. I use TS to write Node modules. I am not arguing against it I just would like representation of all available alternatives to JS known. Elm is a great functional approach.
What keeps me from using Dart and Elm are using 3rd party packages. From what I have read(at least on forum) is that it is difficult do use 3rd party packages with both Dart and Elm.
Marcus And that was what made me move away from Dart in the first place; the difficulty of using existing JS libraries with Dart. Don't get me wrong, I love TS and use as much as I am allowed and I've had absolutely no issues in implementation or compatibility with other libraries.
On the other hand I like the idea of a fresh new language that tries to tackle the shortcomings of JS and provide a better development experience and on the outset Dart offers just that. But in the meantime by using Dart are you cutting your nose to spite your face when you want to use legacy JS libraries in your Dart app? I know you can interop with JS from Dart but I can't imagine it's completely flawless which I think is what holds Dart back when people propose it to their teams.
I'm just seeking knowledge, though it's probably best I try it myself. I may be surprised.
Rob I'm actually keen to start using Aurelia as well, want to use it with KotlinJS.
Marcus I'm using plenty of third-party libraries with Dart without issues. I'm actually using D3 and some Foundation6 (and their JS) with Dart without issues.
Rob JS interop is pretty powerful, using dart:js import, I can easily do this: context['console'].callMethod('log', [message]); which allows me to call JS methods directly from Dart.
Marcus The == is just one example, another example is adding two items, in one place you change it from one type to another and forget about it in another place and JS decides to cast it for you causing weird bugs. In Dart that would simply be a compiler error.
This is also caught by the TS compiler.
Marcus I did not know that, TypeScript sounds like a sane way to use JavaScript directly. KotlinJS has great support for TypeScript, so maybe it's time to get into TypeScript as well.