Live data from Hacker News

Dart/Flutter now has macros/metaprogramming

github.com

21–30 of 129 posts

Re: Dart/Flutter now has macros/metaprogramming

#21

to anyone that has not used it, dart is an excellent language * instant compilation * amazing tooling * null safety * typed I could go on.

I'm not really sure where it slots in in a world with a lot of programming language choices. Why would I use it over something like Rust, Go, or even JavaScript?

>Why would I use it over something like Rust, Go, or even JavaScript?

Honestly, mainly for flutter. But if you do chose flutter for your project, you will suddenly wish everyone was using dart for everything else instead of Java on android, or c#/Swift on ios ect. if that makes sense. If sound type checking is truly feasible on the web then I'd say dart should be there too. But I can't say if that's really the case. At least ECMA seems to think it isn't, at least for js.

Re: Dart/Flutter now has macros/metaprogramming

#23
post #2

This is the actual spec: https://github.com/dart-lang/language/blob/main/working/macr... Not really sure what the linked repo is about.

Thanks for linking the spec. It has been a living document for a long time. I discovered that the implementation had made it into the SDK's master branch. Since it's very early stage and lacking documentation, I made this repo which demonstrates creating a macro that implements some of the most popular codegen functionality Flutter developers use.

Ah, gotcha, very cool. Sorry I just wasn't sure what I was looking at with the repo.

Re: Dart/Flutter now has macros/metaprogramming

#25

Earlier quoted context omitted.

Come for the Flutter, stay for the extras.

Exactly. I use it for a full stack mobile app development. Backend and frontend can share code. Server can be compiled to a single machine code binary.

That’s really interesting and compelling. What’s the rest of your backend stack look like? Do you get good performance from the database drivers written in dart?

Re: Dart/Flutter now has macros/metaprogramming

#26

to anyone that has not used it, dart is an excellent language * instant compilation * amazing tooling * null safety * typed I could go on.

I'm not really sure where it slots in in a world with a lot of programming language choices. Why would I use it over something like Rust, Go, or even JavaScript?

Basically seamless multiplatform targeting - iOS, macOS, Linux, Windows, Android, web

Re: Dart/Flutter now has macros/metaprogramming

#27
post #7

Earlier quoted context omitted.

It's more akin to Java's annotation processor. It's generating code at compile time and not runtime. Dart has runtime reflection and annotations that predate this. The benefit of making this compile time are mainly performance.

Don't discount the developer experience too. With the codegen annotations, you either have to check in your .g.dart files to git which could be stale and break compilation in CI, or have them generate in CI, which is unnecessarily slow and eats up CI minutes. Added bonus is the macro API is less complex than the codegen API.

> or have them generate in CI, which is unnecessarily slow and eats up CI minutes.

Maybe I'm missing something since I'm not that familiar with Dart, but wouldn't Macros use the same amount of time to run and compile?

Either you're processing my_thing.dart and writing out my_thing.g.dart and then compiling the whole thing -or- you're processing my_thing.dart and writing out the new stuff to something in memory and then compiling the whole thing. Right? The amount of time it takes to generate the methods should be the same between the two and then the time to compile the same methods with the same code should be the same as well, right?

Again, I'm not that familiar with Dart and maybe the source generators have drawbacks that I'm unaware of, but it seems like the macro would be doing the same compile-time work (just without emitting the code to a file). I'd love to know what it's doing differently if that isn't how it's working.

Re: Dart/Flutter now has macros/metaprogramming

#28

OP, can you clarify what you mean by the tittle? You have been able to enable Macros as an experiment for a while now, right? And Macros still haven't achieved GA, so I'm not sure what has changed. Is there some point I'm missing here?

Not OP, but you're right, it's still an experiment.

Re: Dart/Flutter now has macros/metaprogramming

#30

Earlier quoted context omitted.

I'm not really sure where it slots in in a world with a lot of programming language choices. Why would I use it over something like Rust, Go, or even JavaScript?

>Why would I use it over something like Rust, Go, or even JavaScript? Honestly, mainly for flutter. But if you do chose flutter for your project, you will suddenly wish everyone was using dart for everything else instead of Java on android, or c#/Swift on ios ect. if that makes sense. If sound type checking is truly feasible on the web then I'd say dart should be there too. But I can't say if that's really the case.…

> Java on android

You mean Kotlin?

Nah. Dart is ok. It doesn't perform as well as those peer languages. It's nice its FFI story is good, but the ecosystem is very weak even compared to Javascript.

As for the tooling. It's decent. I wouldn't call it amazing, unless you come from systems that were anemic to begin with, then it seems pretty amazing.

As for flutter. I recently installed it again. A test app with a single CupertinoTextField consumes 45% of an Intel core on a linux desktop (Wayland and X11 were similar). Like, goodbye. Maybe if WORA means iOS and Android, fine, I get that is the common use case. But that is wishful thinking to false advertising as far as I care.

https://github.com/flutter/flutter/issues/125388

https://github.com/flutter/flutter/issues/101591 (going on 2 years!)

I also believe Google will shit can both this and Fuchsia, because Google is CADT baked into its organizational structure.

Post reply on HN