4 ms·
Does Dart2 offer any compelling features as a language that aren’t also present in Kotlin, Typescript, Swift, or Haxe? I know many users are interested in Flutt
by jitl 6y ago
Does Dart2 offer any compelling features as a language that aren’t also present in Kotlin, Typescript, Swift, or Haxe? I know many users are interested in Flutter - but I’m curious more about the language itself. Whenever I see Flutter examples I’m disappointed I can’t use it with Kotlin (which already has many specialized backends) or some other language with more widespread support outside the Google ecosystem.
- hamstercat 6y agoI come from a TypeScript background, so I can compare it to that. The biggest difference to me was the soundness of the type system, where you're ensured (from a runtime perspective) that objects are correctly typed. This cuts both way: it was great not having to think about typings all the time around input/output, but it was also cumbersome when implementing the internal implementation. I'm a bit biased because I've come to think in term of structural typing much more. Typing in Dart reminded me more of my time with C#. Null safety was a huge missing piece though, glad to see it being added.
- smichel17 6y agoIs there any language that does both? I've really enjoyed js/ts's structural typing for prototyping, but there are certain places I miss nominal typing, particularly with input validation (and other "primitive type, plus restrictions") scenarios. For example, an integer that's used to index into an array, so it must be positive. Or a string that's a valid street address. You can maintain that info by packing it into a unique structure (ie, wrap in an object, using a unique key), but that's awkward to access. Or you can always pass around the parent object (eg, House), which has a unique structure, but then you're introducing unnecessarily tight coupling which is a disaster to maintain.
- emptysea 6y agoIf I understand correctly you want "new types" in typescript, which can be done either via a library or by hand rolling it: - https://github.com/gcanti/newtype-ts https://github.com/gcanti/newtype-ts - https://github.com/Microsoft/TypeScript/issues/4895#issuecomment-401067935 https://github.com/Microsoft/TypeScript/issues/4895#issuecom... but it isn't as nice as say Python's `typing.NewType` or Haskell's `newtype`
- markdog12 6y agonewtype dart proposal: https://github.com/dart-lang/language/blob/master/working/static%20wrapper%20types/feature-specification.md https://github.com/dart-lang/language/blob/master/working/st...
- bgschiller 6y agoThere are a couple of attempts in that direction with TypeScript[1,2]. A bit more work than if there was direct language support, but I've used "branded types" to distinguish between UserIds and ProductIds, between different types of currency, and between different unit systems. 1: https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/ https://spin.atomicobject.com/2018/01/15/typescript-flexible... 2: https://basarat.gitbook.io/typescript/main-1/nominaltyping https://basarat.gitbook.io/typescript/main-1/nominaltyping
- jolux 6y agoI believe classes are nominally typed in TypeScript. Otherwise, OCaml has row polymorphic records, polymorphic variants, and a structurally typed object system, in addition to a powerful nominal type system with ADTs and higher-order modules and such.
- RivieraKid 6y agoI find Dart comparable or maybe even slightly better than Kotlin, not sure why exactly, some things I like: - Overall the language is simpler and more regular, it's easier to read it. - Async / await is way simpler and less mentally taxing than Kotlin's coroutines.
- loic-sharma 6y agoCould you say more about your experience of Kotlin's coroutines vs async / await? I'd love to learn more about that! :)
- jitl 6y agoKotlin’s coroutines are mind-bending to me. They multiply all the spooky fears about threading correctly times a second order of semi-deterministic scheduling logic. The API surface around coroutines is also very complex. Javascript provides one simple API for creating a promise object, and a simple model for how async functions interact. On the other hand, Kotlin suspend funcs need to be “launched” or “run” on a coroutine context which may or may not actually allow async behavior, be backed by a thread pool, and transition between schedulers (?). Kotlin coroutines are very flexible but with that power comes a lot of confusing complexity.
- timsneath 6y agoOne of the big attractions for Dart is that it compiles to native ARM code on iOS and Android, compiles to Intel code for (today's) desktop platforms, and transpiles to JavaScript for the web. There are other high-level languages that support _some_ combination of these targets, but often there are significant differences between implementations (e.g. not all are of production-quality, differences in memory management or threading approaches, inconsistencies in implementation or APIs).
- markdog12 6y agoTo be picky, and for those reading, Dart no longer uses the same "threading" approaches. Dart 1 used Isolates for the vm and web. Dart 2 uses Isolates for vm, aot, but web workers for the web. Of course with Dart 1 it compiled to web workers, but had the same Isolate abstraction. Unfortunately, the Dart web worker implementation isn't very convenient and I think some work could be done there to make it nicer to use. It's a very important use case for today's devices.
- satvikpendem 6y agoIt compiles to JS, ARM, and x86, for web, mobile and desktop support respectively. Also, Dart has code generation so you can write your own language features, like the freezed package which implements algebraic data types even though Dart doesn't have them natively.
- markdog12 6y agoYeah, I'm not a huge fan of the current code gen methods. They're pretty hackish and ugly. I understand it's prob the only option right now. Need partial classes: https://github.com/kevmoo/language/blob/5a1e560bb0871f07f68206c8e39b01802290de65/working/0678%20-%20partial%20classes/feature-brainstorm.md https://github.com/kevmoo/language/blob/5a1e560bb0871f07f682...
- eat_veggies 6y agoDoes freezed feel nice in day-to-day use, or is it more of an incomplete/leaky hack? I'm planning on writing a library in Dart that implements a custom TCP protocol, and I think ADTs would be the best fit for capturing all the valid states and error conditions. I really don't want to have a bunch of nullable fields or use the visitor pattern :/ I've been tracking this issue [0] and hopefully with the release of null safety, the team will have the time to implement ADTs! [0] https://github.com/dart-lang/language/issues/349 https://github.com/dart-lang/language/issues/349
- agumonkey 6y agoForgot what but I remember feeling quite inspired by some of the abstractions .. seemed just slightly innovative yet solving a problem too.
- hopia 6y agoDart feels slightly less versatile than Typescript but has type soundness. Both feel highly verbose to me, but maybe that's just cos I'm used to something with quite minimal syntactic overhead. Ultimately, they're very similar as languages so it wouldn't take long for a Typescript developer to picn up Dart or vice versa.