An experienced C++ programmer (that's me) is venturing into other programming languages and considering the value of learning more about D 2.0. The clean, fresh rewrite of D has caught my eye with its pragmatic and wise choices. Now, I'm eager to delve deeper and explore whether it is possible to:
- Write code in D 2.0. (Potentially a well-defined subset of D 2.0.)
- Compile the aforementioned code.
- Obtain Javascript source code from this compilation process.
In essence, I am seeking a D 2.0 compiler with a capable backend for generating Javascript.
My inquiry consists of two main parts:
- Does such a compiler already exist?
- If not, and if I were to build one myself, where would be the best starting point?
To provide context, the reason behind my quest is to develop a set of business logic in D 2.0 and then utilize that logic in a purely Javascript-based web application (without involving Flash, Silverlight, or Java).
Update
I have received three responses - two relevant and one unrelated which was disregarded.
@FeepingCreature suggests that it may never happen due to being "incongruous with D's targeted environment." I have inquired further on this aspect.
In contrast, @Nekuromento indicates that it can technically be achieved using LDC followed by the LLVM Javascript backend. After checking out both resources, it seems plausible although there are some optimization and minification issues present. Nevertheless, it appears to be functional enough to serve its purpose.
Update 2
Based on current information, here is the most viable approach:
- Utilize LDC as suggested by @Nekuromento since it combines Digital Mars with an LLVM backend.
- Channel the output through the LLVM Javascript backend as recommended by @Nekuromento.
- Further optimize the output using Closure as proposed by @BCS.
I will select the best solution soon but would appreciate additional informed opinions.
Update 3
To elaborate on the reasoning behind this endeavor:
For instance, one specific project I intend to undertake is a geometric modeling library authored primarily by myself over the course of several years, amounting to around 100,000 lines of code. The goal is to minimize bugs to the greatest extent possible, hence avoiding development in Javascript. It should operate across servers, desktops, and browsers without requiring plugins like Flash, Silverlight, or Java. Given the persistence of Javascript within the browsing landscape, strategies need to be devised accordingly.
Update 4
Although I hoped for more responses, I appreciate all the feedback provided, including the insightful comments from @dsimicha. Disagreements are welcomed in a constructive manner. I have accepted the answer given by @Nekuromento.
Update 5 2018-07-18
With advancements in technology, LDC version 1.11 now supports compiling and linking to WebAssembly. More details available here.