
Dart's Macro Language - tosh
https://docs.google.com/document/d/1-We05W0xsd5hTWGsTDCY6pibf2EmmTAsm-4EhIFZoOA/
======
randomfool
I disagree that Dart's code transformers are comparable to Macros- their
intent is runtime optimization- take valid code which runs fine in the VM and
optimize it for dart2js compilation.

This feels more like an advanced compilation feature than macros which are
typically used to encapsulate a set of complex operations.

~~~
skybrian
Code transformers are more general than macros and I focused on one way to use
them. I disagree that they're an optimization in this example, since the
original code isn't being transformed but rather overridden with a separate
implementation. It's more like overriding a method in a subclass; the intent
is probably for the implementations to have equivalent behaviors, but the
details differ and there can be bugs.

Just like when a method is overridden, the reader should be able to see that
there are multiple implementations and understand how they work. If you want
to understand performance, you need to look at the production implementation.

------
tosh
Related:

Notes from last week's DEP (Dart Enhancement Proposal) Meeting
[https://github.com/dart-
lang/dart_enhancement_proposals/blob...](https://github.com/dart-
lang/dart_enhancement_proposals/blob/master/Meetings/2015-05-06%20DEP%20Committee%20Meeting.md)

------
malkia
This reminds me of Turbo Pascal, where certain runtime functions can take
variable arguments, yet the language does not allow defining such. It felt
like magic.

Abother example is lisp, and yes lisp has the ultimate macro language (scheme,
cl, clojure), and yet in Common Lisp there is the notion of "open coded" \-
certain builtin names are known to the compuler/interpreter and can do also
magical things. That to be said certain implementations of C/C++ also have
them.

------
munki
Sort of lost interest in Dart since they dropped the idea of integrating the
VM into Chrome.

~~~
tosh
imho it makes sense to focus more on further improving dart2js to ensure it
works really well across all JavaScript virtual machines and to make interop
with JavaScript & TypeScript super smooth.

The Dart VM (as well as the Observatory) are fantastic. At Blossom
([https://www.blossom.co](https://www.blossom.co)) we currently use the Dart
VM for command line tools but we're looking into using it on the server side
as well.

I guess you were especially interested in the performance improvements that
the Dart VM could bring if it was added to Chrome? I expect that we'll also
see performance improvements for dart2js as JavaScript runtimes become better
compilation targets (e.g. SIMD.js, BigInt, SoundScript, …).

The interesting thing here is that the Dart team can focus on other areas like
…

* the standalone Dart VM

* fletch (an experimental mobile optimized runtime)

* Observatory

* async/await

* libraries (e.g. the new `test` package)

* analyzer (used for semantic code completion & warnings and powers IntelliJ, Eclipse, Sublime, Atom (soon), DartPad see [https://dartpad.dartlang.org/](https://dartpad.dartlang.org/))

* …

and many other things in the meantime. Getting the Dart VM into Chrome and
have it play nicely with v8 is not trivial.

~~~
brodo
When there is no Dart VM in the browser I honestly don't see any advantage
over TypeScript. Two VMs inside each other (with two garbage collectors) will
always be slower and use more memory than just one. Additionally, you always
need to ship the runtime with all your scripts. You also have to use FFI to
interact with Javascript. All the advantages over plain JS you mentioned above
are also present in TypeSctipt (or not needed).

There is also a nice discussion about TypeScript and Dart here:
[https://www.youtube.com/watch?v=5AqbCQuK0gM](https://www.youtube.com/watch?v=5AqbCQuK0gM)

~~~
wtetzner
> Two VMs inside each other (with two garbage collectors) will always be
> slower and use more memory than just one.

Is that how it works? I just assumed it would compile to JS and just use the
JS garbage collector.

~~~
tree_of_item
It does compile to JS and use the JS garbage collector. The posting you're
replying to is very misinformed.

~~~
tosh
As far as I understand you are also less likely to run into unpredictable
performance (runtime bailing out) scenarios using Dart + dart2js.

------
ExpiredLink
He really means macros similar to the C pre-processor?

Dart is a modern dynamic language. Why should it need C-like macros?

~~~
tree_of_item
No, they're not C-like, as mentioned they're AST transforms instead of textual
substitution.

------
kingmanaz
Google, if you're listening, get behind gopherjs. Embrace golang's minimalism.
Pare down your WPL rather than tack on ever more features. Learn from your
successful projects.

~~~
appleflaxen
what is WPL? playlist?

~~~
kingmanaz
Web Programming Language. "Dart is an open-source Web programming language..."

[http://en.wikipedia.org/wiki/Dart_%28programming_language%29](http://en.wikipedia.org/wiki/Dart_%28programming_language%29)

