I have played with Dart a little bit. Although overall the language is interesting and full of potentials, it indeed has some rough edges.
1) Flawed comma operator.
main() {
int i = 1, j = 2;
i = 2, j = 3;
}
Dart will accept line 2 but report a syntax error at line 3. In C and Java, the line is perfectly legitimate.
2) Non-zero integers are different from “true”.
main() {
if (1) print("true");
else print("false");
}
The above program will output “false”, which will surprise most C/Java/Lua/Perl programmers.
3) No “real” dynamic arrays.
main() {
var a = [];
a[0] = 1;
}
Dart will report a run-time error at line 3. Most scripting languages will automatically expand an array. I know disabling this feature helps to prevent errors, but I always feel it is very inconvenient.
4) No easy ways to declare a constant-sized array. As Dart does not automatically expand arrays, to declare an array of size 10, you have to do this:
main() {
var a = new List(10);
}
It is more verbose than “int a[10]” in C.
5) No on-stack replacement (OSR). I discussed this point in my last post, but I still feel it is necessary to emphasize again: if you do not know well how Dart works or are not careful enough, the bottleneck of your code may be interpreted but not compiled and then you will experience bad performance. The Dart developers argued that Dart is tuned for real-world performance, but in my view, if a language does not work well with micro-benchmarks, it has a higher chance to deliever bad performance in larger applications.
6) Lack of C/Perl-like file reading. The following is the Dart way to read a file by line:
main() {
List<String> argv = new Options().arguments;
var fp = new StringInputStream(new File(argv[0]).openInputStream(), Encoding.ASCII);
fp.onLine = () {
print(fp.readLine());
};
}
Note that you have to use callback to achieve that. This is firstly verbose in comparison to other scripting languages and more importantly, it is very awkward to work with multiple files at the same time. I discussed the motivation of the design with Dart developers and buy their argument that such APIs are useful for event driven server applications. However, for most programmers in my field whose routine work is text processing for huge files, lack of C-like I/O is a showstopper. Although the Dart developers pointed out that openSync() and readSyncList() are closer to C APIs, openSync() does not work on STDIN (and Dart’s built-in STDIN still relies on callback). APIs are also significantly are lacking. For example, dart:io provides APIs to read the entire file as lines, but no APIs to read a single line. In my field, the golden rule is to always avoid reading the entire file into memory. This is probably the recommendation for most text processing.
On file I/O, Dart is not alone. Node.js and most shells built upon Javascript barely provides usable file I/O APIs. It is clear that these developers do not understand the needs of a large fraction of UNIX developers and bioinformatics developers like me.
Summary: Generally, Dart is designed for web development and for server-side applications. The design of Dart (largely the design of APIs) does not fit well for other applications. In principle, nothing stops Dart becoming a widely used general-purpose programming language like Python, but in this trend, it will only be a replacement, at the best, of javascript, or perhaps more precisely, node.js. At the same time, I admit I know little about server-side programming. It would be really good if different camps of programmers work together to come to a really great programming language. Dart is not there, at least not yet.
As a pythoh/cython/C developer working in a similar domain space as yours, and eagerly following your programming language explorarations… here you have my point of view.
1) I would rate that syntax issue as a minor annoyance.
2) I do agree: it’s counter intuitive. but at least it’s easy to memorize (contrast it to javascript truthiness …)
3) That exactly the same behaviour of python and a really sensible one IMHO.
a = []
a[10] = 1
which is the “right” default value to use to initialize other values?
4) minor issue IMHO.
5) I’m not really worried by this. Once you know it, it cannot bite you. Moreover nothing prevents OSR by being implemented as already done for v8
6) That’s the most annoying point. very verbose and async API.
PS: have you had a change to explore julia?
On 3), except C/C++, most languages have default values. Nonetheless, probably I should just get used to it. 2) is not a minor issue. Dart should throw an error or follow the rule of other languages. When I forget, I will test integers as I do in C/perl/lua/… 5) is a big issue. It is not right to ask everyone to understand how method JIT is working, and even if we do, the bottleneck is not always obvious. It seems to me that Dart developers do not plan to implement OSR any time soon. They insist the lack of OSR is not an issue for real-world applications – that is only true for web development.
I had a brief look at Julia. It has builtin vector operations. To me, it largely resembles Lua in syntax, including .. 1-indexed arrays, which I do not like. On other down sides, Julia is bond to LLVM, which leads to a large binary. It also lacks a language spec. If Julia cannot provide much more than Lua, I wouldn’t switch to it.