www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Advertise D's great compatibilty with JavaScript

reply Ecstatic Coder <ecstatic.coder gmail.com> writes:
Something I really appreciate a lot with D is how close it is to 
JavaScript.

For instance, I have to maintain two similar versions of Pendown, 
a Markdown alternative for colored documents.

There is a server-side version, in D :

     https://github.com/senselogic/PENDOWN/blob/master/pendown.d

And a client-side version, in JavaScript :

     https://github.com/senselogic/PENDOWN/blob/master/pendown.js

If you look at both file, you should see how close both files are.

Thanks to a few methods (charAt, slice, push, pop, etc) added to 
the string and array types, when I change a function 
implementation in one version, all I have to do is copy-paste the 
modifications in the other file and just make a few minor changes 
(==/===, ~/+, etc).

Everything else works unchanged : string and array methods 
(length, split, join, startsWith, endsWith), closures, etc.

I think that's really AWESOME to have designed the D language and 
its standard library in such a way, keeping it so close to 
JavaScript, the most used scripting languages on earth !!!

That's why I personally advertise it like a "strongly-typed 
super-powered JavaScript", as it is the best scripting language I 
know.

Even if D is obviously much more than that, this still accurately 
describes what many programmers should feel when using this 
fantastic language.

Therefore I think that this closeness is something that should be 
advertised much more, so that people know that :
- a JavaScript programmer will immediately feel at home with D;
- porting text manipulation code back and forth between D and 
JavaScript is just a breeze.
Jun 18
next sibling parent reply Joakim <dlang joakim.fea.st> writes:
On Sunday, 18 June 2017 at 10:38:49 UTC, Ecstatic Coder wrote:
 Something I really appreciate a lot with D is how close it is 
 to JavaScript.

 [...]
Talk to Mike Parker about submitting a blog post, detailing the similarities you see and using this example, for the official D blog.
Jun 18
parent Ecstatic Coder <ecstatic.coder gmail.com> writes:
On Sunday, 18 June 2017 at 16:25:06 UTC, Joakim wrote:
 On Sunday, 18 June 2017 at 10:38:49 UTC, Ecstatic Coder wrote:
 Something I really appreciate a lot with D is how close it is 
 to JavaScript.

 [...]
Talk to Mike Parker about submitting a blog post, detailing the similarities you see and using this example, for the official D blog.
Indeed the following introduction page is missing : https://dlang.org/jstod.html
Jun 18
prev sibling next sibling parent reply Meta <jared771 gmail.com> writes:
On Sunday, 18 June 2017 at 10:38:49 UTC, Ecstatic Coder wrote:
 Something I really appreciate a lot with D is how close it is 
 to JavaScript.

 For instance, I have to maintain two similar versions of 
 Pendown, a Markdown alternative for colored documents.

 There is a server-side version, in D :

     https://github.com/senselogic/PENDOWN/blob/master/pendown.d

 And a client-side version, in JavaScript :

     https://github.com/senselogic/PENDOWN/blob/master/pendown.js

 If you look at both file, you should see how close both files 
 are.

 Thanks to a few methods (charAt, slice, push, pop, etc) added 
 to the string and array types, when I change a function 
 implementation in one version, all I have to do is copy-paste 
 the modifications in the other file and just make a few minor 
 changes (==/===, ~/+, etc).

 Everything else works unchanged : string and array methods 
 (length, split, join, startsWith, endsWith), closures, etc.

 I think that's really AWESOME to have designed the D language 
 and its standard library in such a way, keeping it so close to 
 JavaScript, the most used scripting languages on earth !!!

 That's why I personally advertise it like a "strongly-typed 
 super-powered JavaScript", as it is the best scripting language 
 I know.

 Even if D is obviously much more than that, this still 
 accurately describes what many programmers should feel when 
 using this fantastic language.

 Therefore I think that this closeness is something that should 
 be advertised much more, so that people know that :
 - a JavaScript programmer will immediately feel at home with D;
 - porting text manipulation code back and forth between D and 
 JavaScript is just a breeze.
We should be careful not to make *too* close a comparison. While Javascript is a necessary evil for web applications and some people do like it, I get the feeling that it's becoming less and less liked. It's not quite a fractal of bad design like PHP, but it has more than a few drastic shortcomings and design flaws.
Jun 18
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 18/06/2017 5:29 PM, Meta wrote:
 We should be careful not to make *too* close a comparison. While 
 Javascript is a necessary evil for web applications and some people do 
 like it, I get the feeling that it's becoming less and less liked. It's 
 not quite a fractal of bad design like PHP, but it has more than a few 
 drastic shortcomings and design flaws.
The moment webasm becomes a realistic target, I will do EVERYTHING in my power to get Lua in the browser (yes there already is solutions). Stuff Javascript, kill it, replace it with something actually properly designed!
Jun 18
parent reply Laeeth Isharc <laeethnospam nospam.laeeth.com> writes:
On Sunday, 18 June 2017 at 23:11:25 UTC, rikki cattermole wrote:
 On 18/06/2017 5:29 PM, Meta wrote:
 We should be careful not to make *too* close a comparison. 
 While Javascript is a necessary evil for web applications and 
 some people do like it, I get the feeling that it's becoming 
 less and less liked. It's not quite a fractal of bad design 
 like PHP, but it has more than a few drastic shortcomings and 
 design flaws.
The moment webasm becomes a realistic target, I will do EVERYTHING in my power to get Lua in the browser (yes there already is solutions). Stuff Javascript, kill it, replace it with something actually properly designed!
Why not D? And why wait till it's a realistic target? Wasm is clearly going to be the answer and it's an answer to a problem that exists, so what does one gain by waiting?
Jun 18
parent rikki cattermole <rikki cattermole.co.nz> writes:
On 19/06/2017 2:57 AM, Laeeth Isharc wrote:
 On Sunday, 18 June 2017 at 23:11:25 UTC, rikki cattermole wrote:
 On 18/06/2017 5:29 PM, Meta wrote:
 We should be careful not to make *too* close a comparison. While 
 Javascript is a necessary evil for web applications and some people 
 do like it, I get the feeling that it's becoming less and less liked. 
 It's not quite a fractal of bad design like PHP, but it has more than 
 a few drastic shortcomings and design flaws.
The moment webasm becomes a realistic target, I will do EVERYTHING in my power to get Lua in the browser (yes there already is solutions). Stuff Javascript, kill it, replace it with something actually properly designed!
Why not D? And why wait till it's a realistic target? Wasm is clearly going to be the answer and it's an answer to a problem that exists, so what does one gain by waiting?
(1) eval (2) time+not all API's required are available just yet.
Jun 18
prev sibling next sibling parent reply JN <666total wp.pl> writes:
On Sunday, 18 June 2017 at 10:38:49 UTC, Ecstatic Coder wrote:
 Something I really appreciate a lot with D is how close it is 
 to JavaScript.

 [...]
I don't think that's a good selling point. The obvious reply is "but why should I use an unknown language like D if I could just use node.js and share the client and server code?".
Jun 18
next sibling parent reply Joakim <dlang joakim.fea.st> writes:
On Sunday, 18 June 2017 at 16:31:28 UTC, JN wrote:
 On Sunday, 18 June 2017 at 10:38:49 UTC, Ecstatic Coder wrote:
 Something I really appreciate a lot with D is how close it is 
 to JavaScript.

 [...]
I don't think that's a good selling point. The obvious reply is "but why should I use an unknown language like D if I could just use node.js and share the client and server code?".
Speed, you're limited by the browser but not on the server. I'm running this regex benchmark right now and the D version beats the top C and Rust ones from this list on linux/x64 with a single core: http://benchmarksgame.alioth.debian.org/u64q/regexredux.html I need to parallelize the D version and compare with multi-core also. Of course, once webasm takes off, everyone will simply compile their server code to webasm and ditch javascript altogether: https://blog.figma.com/webassembly-cut-figmas-load-time-by-3x-76f3f2395164 But then, we can sell those javascript programmers on moving to D. ;)
Jun 18
parent Sebastiaan Koppe <mail skoppe.eu> writes:
On Sunday, 18 June 2017 at 18:06:50 UTC, Joakim wrote:
 Of course, once webasm takes off, everyone will simply compile 
 their server code to webasm and ditch javascript altogether.
Although there are proposals to access the dom directly from webasm [1], right now you'll still need js. And I doubt it will change anytime soon. Once it does though -> game-changer. [1]: https://github.com/WebAssembly/design/blob/master/GC.md
Jun 18
prev sibling parent Ecstatic Coder <ecstatic.coder gmail.com> writes:
 I don't think that's a good selling point. The obvious reply is 
 "but why should I use an unknown language like D if I could 
 just use node.js and share the client and server code?".
 I don't think that's a good selling point. The obvious reply is 
 "but why should I use an unknown language like D if I could 
 just use node.js and share the client and server code?".
Ok, I could agree with you. For instance using the same JavaScript code for the server-side version of Pendown would avoid me the dual maintenance. But the D version runs so much faster !!! And I also agree that some people, including me, liked the expressiveness of JavaScript and Node.js, but not its MANY design and implementation flaws !!! This is why I've actually converted ALL my old node.js command line tools to D over the last few months. My github repo is full of them... Because D really "feels" like JavaScript, it was very easy to convert all my Node.js scripts to D. And the resulting tools are all better than before, because D is both JavaScript and C++ done right, fixing all their major flaws in the same time. That's why I always say that D feels like a "strongly-typed super-powered JavaScript". It's clearly a SUPERIOR and BETTER alternative to JavaScript to implement text manipulation tools. And btw I'm still waiting to find something I really dislike in D...
Jun 18
prev sibling next sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On Sunday, 18 June 2017 at 10:38:49 UTC, Ecstatic Coder wrote:
 Something I really appreciate a lot with D is how close it is 
 to JavaScript.

 [...]
This was a good talk last year you might be interested in: http://dconf.org/2016/talks/schadek.html -Steve
Jun 18
parent Ecstatic Coder <ecstatic.coder gmail.com> writes:
 This was a good talk last year you might be interested in: 
 http://dconf.org/2016/talks/schadek.html

 -Steve
Nice pick :) I'm currently planning to use D instead of Go for web development, so I may try such an approach, if I somehow manage to understand how to reproduce it :) At the moment I still use a command-line tool (Basil) to generate the Go structs matching the db design. Very silly, I know, but that was the simplest way I could find to easily keep them in sync...
Jun 18
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 18 June 2017 at 10:38:49 UTC, Ecstatic Coder wrote:
 Something I really appreciate a lot with D is how close it is 
 to JavaScript.
Have you ever seen my jsvar.d ? http://forum.dlang.org/thread/kuxfkakrgjaofkrdvgmx forum.dlang.org
Jun 18
parent Ecstatic Coder <ecstatic.coder gmail.com> writes:
 Have you ever seen my jsvar.d ?

 http://forum.dlang.org/thread/kuxfkakrgjaofkrdvgmx forum.dlang.org
AWESOME !!!
Jun 19