D could have major appeal to academic researchers needing to do numerical computing. The alternative languages I have in mind are R, Python, Matlab/Octave, and Julia. D has some self-imposed limitations that make it a harder sell to academic researchers than should be the case.
Enterprise adoption is the clear goal of the D Language Foundation. Academic research requires a completely different feature set: it should be easy to learn, straightforward to write and read the code, produce correct results by default (even if that comes at the expense of speed), and be fast enough for the things the researcher needs to do. Speed has definitely become more important recently due to large datasets and the heavier use of computationally-intensive methods such as Bayesian inference. That’s clearly an advantage for D.
The experienced D user might be thinking that D is the perfect language for that type of thing. They’d kind of be right, but there are valid reasons it hasn’t seen massive adoption in that sector. Here are four, in no particular order:
matmul(m1, m2)
as is m2.matmul(m2)
. It’s really ugly when there are several mathematical operations being done at the same time. You need matrix multiplication and element-by-element matrix multiplication. Matlab and Julia provide *
for the former and .*
for the latter. With R, it’s *
for element-by-element and %*%
for regular. D does not provide sensible operators to represent both types of matrix multiplication. In this case, restricting operator overloading is not preventing abuse, it’s mandating ugly code with a lower probability of being correct. That’s not an indicator of good language design.2..5
or [2..5]
. iota(2, 5)
wouldn’t be the end of the world if it were part of the language. It’s a PITA to have to do an import for something so fundamental.x[,3..7]
, x[:,3..7]
, x[..,3..7]
, or something similar. This one’s not terrible. You can currently use x[0..$,3..7]
. It’s not as nice, but it’s not the ugliest or most inconvenient thing either.date - 3
to be three months earlier than the given date. The restricted operator overloading means I cannot do comparisons of this type: date >= [2012,4]
. Instead I have to write date.notBefore([2012,4])
, which is far from elegant.-i
the default. Look in the current directory and in the package installation directory/directories.extern(*)
declarations: extern(R)
, extern(Matlab)
, etc. All you need to do is write a wrapper function that converts the arguments of a D function into types that can be understood by the other language. When I say I’ve done it, I mean I wrote a library that takes a D function with signature double foo(double[] x, int[] y)
and creates the function extern(C) SEXP foo(SEXP x, SEXP y)
. The .so or .dll can be loaded by R and called like any other R function. This would be a killer feature for D.I don’t view these as particularly difficult to implement:
extern(R)
declarations to @extern_R
and add a mixin statement. Other languages would require figuring out interop.