Reasons to use D
via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 12 13:52:16 PDT 2015
On Saturday, 12 September 2015 at 20:03:09 UTC, Adam D. Ruppe
wrote:
> That's basically what my D->JS thing did back in 2011.
Nice, so now you will do it again in 2016 ? ;)
> That actually worked somewhat well in my dtojs but it was a
> mild hassle too once function callbacks got more involved. You
> can template them in D but then it bloats the generated JS for
> no real reason since they all have identical dynamically typed
> code!
Yes, you need to convert the D into a JS-specific IR and then fix
it in an optimization step before code gen.
But function overloading isn't enough, unless you accept casting,
since javascript can return anything. I guess you can use
template parameters when you request literal strings like
«document.createElement("div")», but in other situations it might
be more tricky. I don't think function overloading is enough if
you want to avoid casting.
But the TypeScript definition files might make it somewhat
easier, and might be a good starting point as they expose typing
issues. I don't think they are too hard to parse partially:
https://github.com/Microsoft/TypeScript/blob/master/lib/lib.core.es6.d.ts
https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts
https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts
etc
Although I think one should only include what browsers have in
common. So it is a tedious job that probably involves writing a
test program that test what different browsers support and upload
results to a web server...
> I suppose that is solvable too but i never got around to it and
> just went back to writing normal javascript. (I write small JS
> files anyway, it is an ok language for small scripts.)
It's ok if you only write a few hundred lines of javascript, but
the IDE code completion you get with typing really makes a
difference.
More information about the Digitalmars-d
mailing list