Thursday, 11 December 2014

Book Review - 'Mastering Dart'

There's a steadily growing number of Dart books. Is 'Mastering Dart?' by Sergey Akopkokhyants worthy of a place on your bookshelf? Find out in this review!

The book consists of twelve chapters over three hundred and thirty pages, covering a broad range of topics in detail. Topics covered include Async, Reflection, Isolates and Javascript Interoperation. This title goes well beyond the introductory level, even discussing the inner workings of the Dart VM.

It doesn't attempt to cover everything comprehensively - some of these topics (for example HTML5) could easily be entire books in themselves - so have your expectations set realistically there. However it does cover each topic well and in the context of Dart. The chapter on classes feel a little basic at first but it soon goes deeper into Mixins and Generics. Most chapters waste no time at all and go straight into the deep end. No chapter feels like a rushed addition so that another buzzword could be added to the cover!

The layout is pleasing to the eye and clear. The supporting website is also well laid out and the code ZIP file can be downloaded. The credits page shows a good number of eyeballs have worked on this volume including four technical reviewers which boosts confidence in the accuracy of the text. I also appreciated the 12 page index!

I only have a few very minor quibbles with the book - a couple diagrams of the microtasks and event queues would have gone a long way. Also I spotted a few minor typos but nothing major for a first edition.

In summary, this is a good addition to any programmer who has had enough of introductory texts and wants to go deeper with Dart and understand some of its internal workings. It is very readable and I will keep it close to hand. Recommended.

(Packt Publishing were very helpful in providing an electronic version of the book for me to review. This is a genuine review and not an advert.)

Monday, 8 December 2014

Munching Squares

Munching Squares is a graphical that goes back to the PDP-1

The code (available on GitHub) is very simple and easy to experiment with:

  for (int x = 0; x < 256; x++) {
    for (int y = 0; y < 256; y++) {

      ch = (x ^ y) % 256;

      c2d..fillStyle = "rgb(0, 0, $ch)"
         ..fillRect(x, y, w, w)
         ..fillStyle = "rgb($ch, 0, 0)"
         ..fillRect(256 + x, y, w, w)
         ..fillStyle = "rgb(0, $ch, 0)"
         ..fillRect(x, 256 + y, w, w)
         ..fillStyle = "rgb($ch, $ch, 0)"
         ..fillRect(256 + x, 256 + y, w, w);
Changing the x^y to have constants or a different operator yields different results. As this is rather a static demo, I have not included a live Dart version this time. If you want a couple of exercises, try cycling the colours using a timer or sliders to adjust the size. Have fun with it!

Update Thanks for the suggestion from Seth Ladd to use the cascade operator '..' which helps make the code much more readable!

Thursday, 4 December 2014

Coming Soon On The Blog and Dart Releases

After spending November writing a novel, it is great to get back to spending time with Dart! Coming up on the blog this month will be a review of 'Mastering Dart' published by Packt. Also there will be some colourful Munching Squares.

Dart 1.8 was released just days ago but, in keeping with the rolling development, 1.9 has already appeared in the dev channel. Dart 1.8 includes experimental support for ENUM's.