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.