Dart in Action |
Author: Chris Buckett Dart is Google's "other language" but it could be important and there is a need for a good book to explain why Google thinks it's worth the effort. Dart is designed as a replacement for JavaScript and one of the motivations for reading a book about it is to find out how good a replacement it is. Part I of this book is a broad overview of Dart. To really understand it you need to be a reasonable programmer in C#, C++ or Java. The reason is that Dart is essentially JavaScript with a thin layer that makes it look a bit like any of these class-based, object-oriented languages. If you are a JavaScript programmer then you might find some of the ideas more difficult because you have never had to deal with things like class and interface.
Chapter 1 provides a more or less complete overview of everything covered by the book. The initial look at the Dart language made me enthusiastic to try the language out for real. It is the mark of a good book on any programming language if it succeeds in making you feel like downloading and experimenting with a program or two. For the experienced programmer this is a good introduction. The problem is that you might find it a bit too good, because it almost makes the rest of the book redundant. Chapter 1 is more or less the book in a nutshell. From this point the book begins to work its way though most of the material in Chapter 1 only more slowly. Chapter 2 starts at the beginning with a hello world program and an explanation of how to run a Dart program. Chapter 3 deals with working with the browser to create a UI and handle events. Part II is called Core Dart and it expands on many of the basic ideas introduced in Part I. Chapter 4 was where things started to go wrong for me and Dart. It explains how functions are first class objects and how they are subject to closure. At this point what popped into my head was "Just like JavaScript". Chapter 5 deals with libraries and issues of access control. Chapter 6 and 7 introduce classes and interfaces which are really the key plus points for Dart over JavaScript. The book does a good job of explaining them but of course if you already program in a class-based language you will already be convinced that this is a great idea. If on the other hand you are a JavaScript programmer you will understand the ideas but you might not be so convinced that they are such an advantage. You might even want to add that the latest version of JavaScript has an almost identical construct. Chapter 8 introduces collections, which is a good use of the class/interface idea. However, at this point we meet the idea of generics. This is another fine and obvious idea if you already know a strongly typed language, but to the JavaScript programmer it is the fix for a problem that JavaScript doesn't have. If you don't have strong typing there is no need for the complication of generics. While the book explains the mechanism of using generics well, it fails to discuss the advantages in a way that explains the philosophy and it would leave most JavaScript programmers wondering why.
Chapter 9 introduces asynchronous programming and this will be very familiar to any JavaScript programmer - events and callbacks. The Future and Complete objects are then introduced and this will be new to many programmers and introduces a great plus point for Dart. However, you get the same sort of functionality from jQuery's Deferred and Promise objects. It arguably isn't as good as C#'s approach - async and await. This brings us to Part III on client-side Dart apps. This is really a collection of techniques that allow Dart to work in the browser. Chapter 10 explains the idea of a single page app, but the feeling of deja vu is strong in the section on building a UI which was introduced in Part I. Chapter 11 is about offline data and includes sections on web storage and - sort of ironically - JSON. It seems that you can't avoid JavaScript, even in Dart. Presumably a Dart encoding for data is possible? Chapter 12 is all about integrating with JavaScript and other systems features such as AppCache and so on. The final part, IV, is about server-side Dart. Here Dart takes on Node.js, which is not a role many non-Dart experts would expect. Chapter 13 introduces the idea of running Dart on the server and the details of the HTTP server object. Chapter 14 is about web sockets and using CouchDB.The final chapter is about concurrency and isolates - Dart's unit of concurrency. If you want to learn Dart this is a very good book and I can recommend it. However, if you are not so sure about Dart then in the end it didn't really convince me that it was any better than using JavaScript - not better, just different. The book seems to be working from the assumption that the reader just knows that JavaScript, weak typing and so on are bad, and that strong typing, class-based objects and so on are good. There are arguments made for this point of view, but in the main the book just explains Dart with a few words of encouragement. As a result I can recommend the book, but I'm still not sure about Dart.
|
|||
Last Updated ( Tuesday, 21 May 2013 ) |