Experiments with emscripten and D
Piotr Szturmaj
bncrbme at jadamspam.pl
Sat Aug 17 09:43:13 PDT 2013
W dniu 17.08.2013 16:42, Gambler pisze:
> On 8/15/2013 5:55 PM, Piotr Szturmaj wrote:
>> bearophile:
>>> Piotr Szturmaj:
>>> I have found some related activity from Rust people:
>>> https://github.com/mozilla/rust/issues/2235
>>> https://github.com/Yoric/Mozilla-Student-Projects/issues/33
>>> https://mail.mozilla.org/pipermail/rust-dev/2012-April/001607.html
>>>
>>> Once your work is more more completed, the dlang site could show (in a
>>> sub-page) the compiler that compiles the online examples of the docs
>>> that's able to produce html+JS on the fly from the D code written in the
>>> browser.
>>
>> Yes, and it could be used to write rich web applications (which is the
>> reason I'm working on it). JavaScript certainly wasn't created for big
>> codebases...
>
> Never understood the excitement about things like these. Yes, it's
> somewhat interesting and technically impressive, but in the end, the
> only language that benefits here *is* JavaScript. And it's already
> spreading like cancer. Why help it if you don't like it?
>
> If even 1/10th of the effort spent on compile-everything-to-JS projects
> was directed towards properly bringing other languages into the browser
> land, the web would be a much better place now.
It's not about helping JavaScript. It's about using another language to
do client side scripting. I hate JS, I really don't like to write bigger
applications in it.
What happens when you forget a semicolon or a comma? Or make some typos?
It silently breaks. I don't care if there are tools to help with it.
It's still a mess. Did you see WAT
(https://www.destroyallsoftware.com/talks/wat) ? If not, please do. Here
are some examples of JS "additions" which WAT demonstrated:
[] + [] // yields empty string
[] + {} // [object Object]
{} + [] // 0
{} + {} // NaN
Seriously, WTF!
And again, I don't want to write in it, but I _must_ use it. I just want
to use another language that translates to JS. There are many of them
already. Still, no one is even close to D in its usefulness.
The whole problem is that you need to write a web applications _now_,
when the only supported languages for the web is JS. You really don't
have a choice. Even if other languages could be widely supported from
today, you'd still have to support older browsers. This means JS will
stay in for another couple of years.
>> The other big advantage would having one codebase shared between server,
>> browser (including mobile) and desktop apps.
>
> Yes, in theory. In practice, this is just something Node.JS people came
> up with for advocacy of their platform. It's false. In-browser
> JavaScript has so many constraints imposed on it that it will never
> behave exactly like server-side code. (For example, your gist doesn't
> work in IE. Not that I use IE normally, but you get my point.)
Obviously, you can't share every possible code. It's about sharing the
cross cutting parts. Imagine an application with a server, web frontend
and desktop frontend. With shared codebases, you could write one client
code. Just use the same abstractions for the web and for the desktop.
Then you can create similar interfaces from the same codebase. It's a
huge win. Duplicating efforts is tiresome, error prone and obviously
takes time.
> Worse, no one took time to actually design a sensible model of
> interaction between server and the client for a "shared" codebase. It's
> all a jumbled mess of ad-hoc implementations and subverted web
> technologies that were originally meant for an entirely different
> purpose. I sometimes see JS examples like this:
>
> if (imOnTheServer){
> //do one thing
> } eles {
> //do another thing
> } //Yay, "shared" code!!!
>
> Every time I do, I get the urge to abandon programming and change my
> occupation.
This is not a new idea. Morfik is a webdev tool that automatically
splits your code to the server and JS. I remember it was available in
2005. Also, there is Opa language.
I don't see anything wrong with cross platform code. For D example, I'd
imagine it could look like this:
void showMsg(string s) {
version (JS)
js.alert(s);
else
YourDesktopWidgetToolkit.showMessageDialog(s);
}
void main() {
showMsg("hello world");
}
Compiled with a regular compiler and GTK, will show a dialog.
Compiled with emscripten-like compiler will show a message in the browser.
More information about the Digitalmars-d
mailing list