17 ms·
The road to Dart 3: A fully sound, null safe language
- dom96 4y agoDart is one of those languages that has always felt obscure to me, even though there appears to be a lot of work put into it. What are folks using it for?
- jolexxa 4y agoIt’s used with Flutter, Google’s app development framework. I really enjoy Dart as a language, but it is fairly young and missing a few conveniences (such as data classes). It also can’t compile to dynamic libraries, only executables. Despite that, it is very pleasant if you enjoy managed languages.
- deleted 4y ago[deleted]
- hota_mazi 4y agoIt's used in Flutter exclusively, and since Flutter is hardly used at all, it's a pretty unknown language, and will probably always remain so. It doesn't help Dart that Kotlin and Swift have been null safe languages for a decade now.
- amgreg 4y agoI wouldn’t dismiss Flutter out of hand. It’s more popular even than React Native! https://stackoverflow.blog/2022/02/21/why-flutter-is-the-most-popular-cross-platform-mobile-sdk/ https://stackoverflow.blog/2022/02/21/why-flutter-is-the-mos...
- jimbob45 4y agoMore popular by the metric of...StackOverflow question tags. I'm not sure that I would use that as my preferred metric for language popularity.
- wizofaus 4y agoIndeed the perfect language/tech stack would be immensely popular and never have any SO questions, as everything would be obvious and easy to figure out without help...
- UncleEntity 4y ago… which is why hairdryers have warnings like “do not use while sleeping”. I mean…
- hota_mazi 4y agoNot a very meaningful metric. Take a look at job boards and see how many job postings you find for React compared to Flutter.
- thomascgalvin 4y agoI taught myself Dart a couple of years ago, and enjoyed the language, but never found a compelling use for it. For anything I might do in Dart, there's a better alternative. For backend stuff, I'm going to write in Java or Kotlin. For frontend stuff, I'm going to write in JS or TypeScript. I like Flutter, but Flutter by itself isn't reason enough to adopt Dart. Long term, if Jetpack for Desktop actually takes off, I don't see any reason to write in anything but Kotlin.
- sroussey 4y agoI think there was a fork of Chrome that included Dart as another language runtime alongside JavaScript.
- digitalsankhara 4y agoThat rings a bell with me. I think is was during the early days of Dart and it was a special Chromium build if memory serves me.
- markdog12 4y agoYep, Dartium. That ship has sailed years ago.
- jamesfinlayson 4y agoThat was Dart 1.0 which I think was weakly typed.
- ljw1001 4y agoWhat is the state of dart for cross-platform development? I looked a few years ago and it seemed like progress was being made for web development and desktop use, if I remember correctly.
- tluyben2 4y agoWeb development is not really going well (imho), but desktop I find good enough to at least prototype with. Wether I can make my mind up if I like Dart or not, Flutter really feels right to me.
- anon23anon 4y agoare you using flutter just for the vanilla use case of a mobile app?
- tluyben2 4y agoMobile + Desktop. But these are LoB apps. I just like it better than React(Native). The results are really robust and easy to debug if something wrong. Also when I do an update, unlike React, not suddenly everything is broken.
- vsmenon 4y ago[I'm the eng lead for Dart.] Dart itself is used heavily on the Web by Google. E.g., ads.google.com is a Dart web app - but not a Flutter one. It uses a Dart version of the Angular framework. It's probably the largest Dart app in existence today. Flutter on the Web is less mature, but (IMO) making good progress.
- tluyben2 4y agoThat's excellent to hear! I did not know (my lack of research in that regard obviously) that Dart was used that much outside Flutter! I really like Flutter and see them as married, but I'm obviously wrong. Thanks for the explanation.
- 4y ago
- pizlonator 4y agoI don’t buy that null is a billion dollar mistake. Just because some dude with a fancy name said so doesn’t mean it’s true. In particular, how many dollars does it cost to have null safety, and how many more does it cost to use it? I feel like folks quoting Hoare never even bother asking this question.
- chomp 4y agonull itself isn’t the billion dollar mistake, it’s that literally every object can be T|null. Undefined or null is actually quite useful, as long as you’re expecting it.
- disintegore 4y agoNull safety means you can't dereference a null pointer. Therefore something like `T | null` is not possible, because `null` doesn't exist. What you'd have instead is an Option or Maybe type and a compiler that requires exhaustive handling of it.
- masklinn 4y agoIn the informal context of GP’s comment, null is a singleton type whose sole value is null. That exact syntax (modulo langage divergences) is one of the options for “nullable” in Python: https://docs.python.org/3/library/typing.html#typing.Optional https://docs.python.org/3/library/typing.html#typing.Optiona...
- disintegore 4y agoWhich can still lead to unrecoverable runtime errors, that could otherwise be compilation errors.
- masklinn 4y agoWhat are you talking about?
- frou_dh 4y agoIt seems there's often a need for languages to evolve towards sanity rather than being sane out of the gate.
- ghqst 4y agoI missed the part where language design is a solved problem and everyone is able to create a perfect programming language on their first try. Do you want every language to just be slightly different Rust?
- frou_dh 4y agoIn that respect it's more about ML/SML from the 1970-80s. Even putting null-safety aside, the latter part of the post with destructuring tuples and pattern-matching shapes looks almost 1:1 like SML code!
- munificent 4y agoI'm the main designer of the patterns stuff we're working on in Dart. Yes, SML is absolutely one of the primary inspirations. The design also takes a lot of inspiration to how Swift and C# approach pattern matching and destructuring. There are so many good languages out there to learn from.
- mrkeen 4y ago> Do you want every language to just be slightly different Rust? Kinda. The trap with putting out 'crap' and fixing it later is that language designers will inevitably try to preserve backward compatibility, meaning the crap has to stay in forever. Putting null and null-safety into a new language is like putting venereal disease and condoms into a new language. People will spill paragraphs on whether or not condoms are worth it, and whether VD is a problem if you have a sufficiently advanced IDE. But why put the VD into the language in the first place?
- hajile 4y agoThese sound like amazing advancements. Now they just need to add a builtin Option<T> to all the things.
- munificent 4y agoI really like option types in languages that were designed around them, but given Dart's history as an imperative C-ish language with millions and millions of lines of code out there, I think nullable types are a better fit for the way users think about and work with the language. It's really hard to do both approaches. (The fact that Java has an Option<T> type, but all references to it are also nullable, is sometimes a source of chagrin and sometimes hilarity to me.) If you want a nice user experience, consistency across the ecosystem is huge. So when we decided what to do about statically checking for null reference errors, we went with nullable types (the same as Kotlin, TypeScript, and C# do) instead of option types (Swift, Rust, etc.). I wrote a long thing about my thinking on it here if you're curious: https://medium.com/dartlang/why-nullable-types-7dd93c28c87a https://medium.com/dartlang/why-nullable-types-7dd93c28c87a It's a real trade-off. There aren't perfect solutions. Option types have some nice composability properties, but they tend to be more verbose and don't play as nice with the imperative control-flow heavy code that's idiomatic in C-derived languages.
- johnthuss 4y ago"For Dart, we chose the path of sound null safety." Null Safety is the killer feature of modern programming languages like Swift and Kotlin. It provides a clarity you just can't get otherwise and saves you from runtime errors. And it requires very little additional ceremony to use.
- IshKebab 4y agoI'd say it is more like a basic requirement than a killer feature at this point.
- johnthuss 4y agoWhile I love null safety, It's hardly a given. For Dart in particular, it sounds like there was a serious discussion about the choice, and it could have gone the other way. (edit: removed incorrect statement about Python's type safety)
- masklinn 4y ago> languages like Python that don't provide any static type safety https://docs.python.org/3/library/typing.html https://docs.python.org/3/library/typing.html https://github.com/python/mypy https://github.com/python/mypy > let alone null safety https://docs.python.org/3/library/typing.html#typing.Optional https://docs.python.org/3/library/typing.html#typing.Optiona...
- The_Colonel 4y agoFWIW my (1 year old) experience with mypy was very poor. Stuff breaking between releases, wrong resolution, bugs. It kinda felt like a 3rd party fun project, not an official high quality solution. The fact that the source can contain completely wrong declarations and Python will happily run it anyway felt really bad. It's kinda like JavaDoc rather than a classic type system.
- IshKebab 4y agoLanguages like Java, Go and C were all designed before it became obvious that `Option<>` or `?` were obviously the right thing to do. You can live with it, but most language eventually add some way to deal with it. Java has @NonNull. Javascript and Python both have static type annotations that are non-nullable. Even C++ has some attempt at it (std::option<>). The only one I know of that hasn't bothered trying is Go.
- nu11ptr 4y agoI love the idea of sound null checks, but doesn't Dart also have unchecked exceptions? To me it seems a bit weird to focus so heavily on type soundness when at any moment a piece of code could throw an unexpected exception that kills your program. I realize these are very different features, but a language is more than the sum of its parts. While I realize every language has some level of unchecked exceptions out of necessity (ie. panics on divide by zero, etc.), they are not meant as general level error checking, but as more of a "can't continue - things are that bad" kind of mechanism. In summary, if they are that convinced sound null types are needed, to me it needs better error handling that matches the same level of discipline. That said, any and all improvements are always welcome, so I do think overall it is cool they are taking this seriously.
- hajile 4y agoOne step at a time. They don't want a Python 2/3 situation.
- jnwatson 4y agoWhy? Swift has never worried about it, and Dart’s target market is a lot closer to Swift. Swift has made large backwards-incompatible changes 3 times now.
- alwaysbeconsing 4y agoHow many Swift users consider that a good thing though? Swift is on railroad tracks: you have to upgrade on Apple's schedule or eventually you won't be able push your product to the store. Also, 2 to 3 was a nightmare and the Swift team itself is actually pretty chary about doing anything like that again.
- pianoben 4y agoI've been a mobile dev for many years now. Every team I've been on either largely avoided Swift for the first 3-5 years, or was burned hard due to the constant churn. It's much more stable these days, but personally I'm still wary of the team's (past?) proclivity to make sweeping incompatible changes.
- truth_seeker 4y agoPattern Matching looks good too ! https://github.com/dart-lang/language/blob/master/accepted/future-releases/0546-patterns/feature-specification.md https://github.com/dart-lang/language/blob/master/accepted/f...
- latchkey 4y agoI'd love to see Dart break out of just being the language for Flutter. I built an app in Flutter and Dart was quite fun to learn and work with. Will it ever break out of its shell?
- that_guy_iain 4y agoConsidering it just started to get any traction by being the language of Flutter, it'll probably take some time. Remember Dart originally came out around the same time as Go. And people are just starting to actually use it for things in production.
- allenbrunson 4y agofor me personally, it already has. i have a large set of scripts i use to automate the boring parts of my job. i originally wrote them in bash. past a certain amount of complexity, that became unworkable, so i ported it all to python. after about a year, i found python to be too limiting as well, based on my own coding style, so i am porting it all again, this time to dart. the dart compiler makes it a cinch to create command-line apps that work on basically anything with a terminal.
- Apocryphon 4y agoInteresting, what made Dart less limiting than Python?
- allenbrunson 4y agooh man, so many things. i'll choose the most annoying for me personally. let's say i am creating a new dart source file in a dart package, something i have to do quite often. the import section will look like this: import "package:crystal/crystal.dart"; super easy. i can add it from memory, or copy an existing module in this package, which will already have that line at the top. it is extremely rare that i ever need to modify this, or add a second line to the import section. meanwhile, let's say i am adding a new python source file to a package. the import section will end up looking like this: import os, base, dart, execute from typing import List, Optional from .build import build from .build_args import BuildArgs from .build_type import BuildType, buildTypeList, buildTypeParse from .build_type import buildTypeStrings, buildTypeValid ... and pretty much every change to this source file will require modifying the imports section, in ways that i definitely have not memorized, even after years of python programming. trying to write a large program in python was, for me, death by a thousand paper cuts like this, which don't occur in dart.
- jmyeet 4y agoSome claim null is a mistake. I will counter and say that null not being exportable within the type system was the real big mistake. Languages where you can express if something can be null or not are a joy to work with and remove a whole class of errors. That being said, I still don’t really understand the value proposition for Dart. Through different versions it’s morphed in the classic solution-looking-for-a-problem way (eg the optional typing). Did we really need this when Java, JavaScript, Python and Go existed?
- account-5 4y agoI'm glad to see this here, I like Dart. HN in general doesn't seem to. IMO for cross platform development Dart is the way to go if you are wanting a single code base and targeting desktop/mobile/web. Some of the things this language can do is amazing. For quick scripts I still reach for python or Linux: bash, Windows: AHK. But if I'm developing an app I now reach for Dart/Flutter.
- cogman10 4y agoMy dislike for Dart comes from being an early adopter and getting burned by it. One of their headline libraries, angular dart, pushed out a broken release that stayed broken for nearly a year. Dart was revived with flutter and I'm glad it's doing better. However, I have trust issues with the way google runs their projects. I simply don't know if they'll continue to support Dart/Flutter or if they'll drop it next year for something shiny. I also don't appreciate the gaslighting that happened on the dart forums. There was a lot of "Oh, dart isn't dead, we are using it heavily and actively in google!" that happened when dart was very clearly abandoned by google. They pulled the exact same stunt with GWT before replacing it with J2CL.
- wstrange 4y agoI don't work for Google (no inside knowledge), but from what I can see, their use of Dart has if anything increased substantially. Dart/Flutter are highly unlikely to be abandoned.
- cogman10 4y agoSorry, I'm not trying to say that google isn't currently heavily using dart. Rather, that between Dart's initial release (released in 2013) and the release of flutter (released 2017) Dart was practically dead. That's the period that left a bad taste in my mouth. IDK who chose to use Dart for flutter, but by doing so they revived a basically dead language.
- flakiness 4y ago
- alefnula 4y agoI'm surprised that no one is commenting on macros. For me, that is the most exciting feature! It'll make writing code so much more enjoyable and avoid all of the code generation happening at the moment. But maybe I'm the only one who's bothered with code generation :D
- markdog12 4y agoYou're not the only one. They actually started work on macros before pattern/records, but for some reason it seems priority changed. I would have much preferred macros came first.
- markdog12 4y agoUpdate: One of the Dart devs says it's because macros are higher risk and harder to get right.
- revskill 4y agoA language without null safety in the design in first place isn't worth my time at all. It's like a "business language" , released with deadline. I've suffered enough burnout and stress for those kinds of languages already. It's enough.
- jgavris 4y agoI'm genuinely curious, and I don't know much about Dart and haven't used it. The comparisons to Kotlin are interesting, especially sealed classes and pattern matching. For this example from the post, is it not possible use an extension method (common practice in Kotlin I've seen and written)? double calculateArea(Shape shape) => switch (shape) { Square(length: var l) => l * l, Circle(radius: var r) => math.pi * r * r }; Aka: extension Area on Shape { double calculateArea() { ... } }
- munificent 4y agoExtension methods (which Dart also supports) are orthogonal to the pattern matchinng going on here. If you wanted to define that example function as an extension method, you could: extension on Shape { double calculateArea() => switch (this) { Square(length: var l) => l * l, Circle(radius: var r) => math.pi * r * r }; } example(Shape someShape) { print(someShape.calculateArea(); } Extension methods are statically dispatched, so they don't give you any way to write code that's polymorphic over the various subtypes. In order to have code specific to each subtype you need something like virtual methods (which requires you to be able to add methods directly to those classes) or type switches (as in the pattern matching like we have here).
- jgavris 4y agoThanks. I'm just wondering why the example didn't show this extension method. It seems more idiomatic to just call it on the receiver instead of passing a parameter.
- munificent 4y agoIt's only more idiomatic if you're coming at this from an object-oriented perspective where anything "dispatchy" should be in receiver position. But once you let go of that notion, it's entirely to just have a function that does a type switch.
- 4y ago
- Alifatisk 4y agoI enjoy Dart a lot currently, but I can only imagine it being used on the client-side for building an ui, nothing else. It even advertises itself like so. To me (with my limited knowledge on Dart), it feels like Dart is lacking a lot if it wants to work as a systems language.
- radicalriddler 4y agoThe main sass implementation is in dart https://github.com/sass/dart-sass https://github.com/sass/dart-sass, which I think is dumb because it's a fair amount slower than the old libsass written in C. The reason they spouted was due to "Low developer resources" due to the difficulty of C, so they swapped to a language pretty much only used by Googlers. Google now has control of sass, which then gives them greater influence (even greater than just having browser majority) over CSS Spec choices (see CSS Nesting spec).
- zem 4y agoI would argue that if someone was interested in working on sass there's a far lower entry barrier to learning enough dart to do so than getting good enough at C to work with the old libsass.
- geyforkotlin 4y agoWhen I first got into Kotlin I thought that null safety was a matter of getting rid of null, like some try to do in their Java code. Now I know that actually it gives me liberty to safely use null wherever I want and not have to worry about it blowing up in my face later. The keys to this is that the language makes it obvious what can be null "Type?" and by giving me ergonomic tools to handle nulls such as ? and :? and compiler non-null inference. I wonder how this pattern of make X visible and give ergonomic tools to handle X could be applied to improve other aspects of programming.
- 999900000999 4y agoFlutter web + Firebase allowed me to create a small web app fairly quickly. Hosted effectively for free so it's been deploy and forget. Dart is a pleasure to work with, I'm not really a CS guy, but it's like Typescript with real types. Better tooling, no NodeJS legacy crap barely holding itself together. I don't know if it'll ever unseat React on the Web though. Once an ecosystem has momentum it's hard to disrupt.