Tuesday, February 3, 2015

An interview with the author of Mastering Dart

Dart is more than just a language. The Dart SDK contains a robust core library (with async classes, collections, reflection and more), HTML bindings, JavaScript interop, a server-side VM, and more. Dart is easy to learn, but when you're ready to "level up", it helps to have an expert guide you through its many features and capabilities. We sat down with author Sergey Akopkokhyants, author of Mastering Dart, to learn more about his book for advanced Dart topics and techniques.



Q) On behalf of the Dart team, thanks for writing Mastering Dart! So, how did you discover Dart?

Sergey: The first time I heard about Dart was in 2011. I watched a Google conference and found it very interesting how this new language helped in developing web applications in a very familiar fashion with OOP, types and generics. Information was scarce at the time, so I worked to collect it myself bit by bit. Late in 2012, Ray Cromwell introduced the idea of migrating from GWT to Dart. I think that idea was still in my mind when I decided to start the Dart Web Toolkit project – a port of GWT to Dart.

Q) What made you want to write a book about Dart?

In September 2013 Packt Publishing asked me to review the book “Learning Dart” by Dzenan Ridjanovic and Ivo Balbaert. That experience was very interesting and when in April 2014 Packt asked me to write “Mastering Dart”, my answer was ‘yes’. English is not my native language, but this challenge was so exciting and intriguing, that I couldn’t ignore it. Without the help of technical reviewers Yan Cui, Predrag Končar, Jana Moudrá and Martin Sikora and editors Sonali Vernekar, Govindan K, Shashank Desai, this book would never have happened. I also wish to express my deep gratitude and appreciation to my colleague Jeffrey Johnson for his valuable feedback and faith in my success.

Q) Who should read the book? Who is the book for?

This book is for application developers who have experience with Dart and want to develop reusable and robust server and client side code in Dart. If you have basic or intermediate knowledge in Dart, but would like to improve your level of expertise and make use of the language in a more effective and comfortable manner – this book is for you.

Q) What makes Mastering Dart special?

This book is designed to help developers make the most effective use of the Dart programming language, its SDK libraries and a rich set of publicly available packages. It focuses on the advanced stuff and doesn’t repeat the basics. Also, it doesn’t fall back on comparisons with other languages for the explanations and examples. The chapters in the book are arranged in such a way that you can easily learn more in a step by step manner. If you feel you have missed something major, go back and read the earlier chapters. You can refer to any chapter that you need to get more in-depth knowledge about. If you have any questions or suggestions about the book please send them on my email or post them in the book's G+ community.

Q) How do you use Dart today?

I have more than 5 projects written in Dart on GitHub, but I mostly use Dart in my job in the commercial sector. I like Java very much but Dart is steadily replacing that.

Q) What advice would you give to a developer learning Dart for the first time?

You need to practice — a lot. This book or any other only gives you a general direction to go in. You need to follow on this path on your own and face the daily challenges – this is your karma. Another suggestion is to read the source code from popular open source projects. This simple practice gives you a lot mental pabulum and helps you create your own code just follow the patterns. So, start you simple project ASAP and build up from there — who knows, you might change the world.

Q) Where can developers follow you and your work?

Find all my open source projects on GitHub. You can follow me on G+Twitter and LinkedIn.

Thanks Sergey! Developers can find Mastering Dart at Packt Publishing or Amazon.

Monday, February 2, 2015

Irregexp, the Dart VM's new RegExp implementation

Crafting regular expressions, or regexps, is an art form. They are a powerful way to search through and pattern-match strings. To give our developers faster performance (up to 150X, compared to our previous implementation) and better semantics with their regular expressions, we're happy to announce that we've finished a port of V8's Irregexp engine to the Dart VM.

Previously, some regular expressions had incorrect semantics, while others had sluggish performance when run in the Dart VM. These issues are resolved by the new implementation. The behavior of regular expressions are now consistent with dart2js compiled code executed on top of V8.

We hope you enjoy these improvements to Dart's regular expressions. Look for the new regular expressions implementation starting with Dart 1.9, which is now in the developer channel.

Posted by Jakob Gruber and Ian Zerny, Irregular Software Engineers

Friday, January 30, 2015

Dart Language Evolution Discussed in Ecma TC52

The Dart standards committee (ECMA TC52) met on January 14th, 2015. The committee discussed several areas where the language could be improved and agreed that these should be investigated in more detail, likely leading to detailed proposals over the next few months.

Configurable Imports

Some libraries only work on the server, or only on the client (in particular, if dart:html has been imported then a server execution is ruled out). There may be added support for some kind of conditional compilation such that different contexts may make different choices about which libraries to import.

Another proposal, which is much more complex and powerful, is concerned with parameterized libraries, e.g., libraries that may take type arguments or other libraries as arguments. Erik mentioned that the conditional compilation feature might already be included in the language, based on the ‘part’ mechanism, and Gilad agreed that that would be worth investigating, too.

Union Types

Union types have been proposed many times, and they have been postponed many times because the flexible nature of the Dart type system makes them less crucial than in some other languages. However, Javascript interoperability creates the greatest pressure for having them, because it is very common to use idioms in Javascript where a meaningful typing in Dart would rely on union types. Other cases could be functions taking an argument of a type T or of type Future<T>, leaving it up to the function to distinguish between the two cases.

First-class functions with different arity is another case. A problem with union types is that they tend to cause parsing conflicts; maybe they could be confined to typedef declarations, but that does not work well with generics; support for local typedefs may help. The operations allowed (when avoiding static type warnings) are just the ones in the common supertype of all operands of the union type operator, i.e., just the operations that are shared among all the types. Avoiding the accidentally shared operations (the ones that are declared independently in several operands) helps greatly avoiding a number of typing related complications.

It should be noted that union types may actually work quite well in Dart, especially because the assignability rules (rather than subtype rules) in the type system allows a value with a union type to be used where any of the operand types can be used.

Generic Methods

Dart does not currently support generic methods (aka polymorphic methods, i.e., methods taking type arguments), because of the strong expectation that they will be supported by type inference, which would add substantial complexity to the language and create conflicts with the basic design of Dart (e.g., the VM might be forced to perform inference at run time at heavy cost, or the reification of types would give user code access to compiler-selected type values, which could change over time due to seemingly remote and insignificant changes in the code). So the generic methods in Dart will not be supported by type inference, all type arguments must be given explicitly or they will be implicitly provided by the compiler as <dynamic..dynamic>. The syntax is not yet settled, and in particular there are ambiguity problems with several proposals (foo(a<b, c>(d)) may be seen as foo(_) or foo(_,_)).

Generalized Tear-Offs

The property extraction mechanism (aka closurization or tear-offs) creates some problems in the language: the current syntax does not work for operators, getters, setters, and constructors, and it is even creating problems for optimization because it is not known before runtime whether ‘a.m’ will need to be executed as a property extraction or as a getter invocation. New syntax is proposed for tear-offs, generally using ‘#’ rather than ‘.’ to separate the receiver and the selector. No particular difficulties are foreseen after an initial review. For backward compatibility, the old syntax and the new will coexist.

Null-Aware Operators

This feature has been requested for a long time! It is simply a small amount of syntactic sugar, but it may be quite convenient and it may be good for code readability. We propose a?.b (the Elvis operator), which just nulls out the result when a is null; a??b which evaluates to the value of b as a default when a evaluates to null; and a ?= b, which sets a to the value of b iff a is null.

Improvements to Type Promotion

This is purely a static type system issue, concerned with the typing of variables for which there is a type test in the preceding control flow. We currently have a few rules about type promotion, deliberately avoiding the highly elaborate versions that so many participants in this debate have requested. These rules are sound, but this is actually not particularly well motivated in a language like Dart. In many cases, users consider the results counterintuitive (“Why can’t it see that x is an int here, I just tested!?”). We may choose to use an unsound approach where the implied intentions of programmers are taken much more for granted, even though there can be exceptions at runtime.

Erik mentioned that if a pluggable type checker could remove certain type warnings then it could be delegated to a pluggable type checker (or several) to perform arbitrarily fancy flow analyses, and do extra type promotion. This means that type promotion in the spec can be very simple, and all the tricky special cases can be handled in a pluggable manner.

Minor Adjustments to the Existing Specification

We may change ‘await throw’ to throw immediately. The rules about type checking usages of objects whose class declares ‘noSuchMethod’ need generalization. The name 'main' should be allowed to be other things than a top-level-function (e.g., a const variable whose value is a suitable closure). Finally, allow doc comments to access imported scope.

Erik mentioned that there is a proposal to revise function type subtyping, and Gilad responded that there may be a need to adjust the specification in this respect, to be discussed at the next meeting.

Thursday, January 29, 2015

An interview with the author of Dart for Absolute Beginners

There are many books about the Dart language and libraries, but most assume some knowledge of programming. For people that are brand new to software development and want to learn Dart, there is now Dart for Absolute Beginners (Apress).We sat down with author David Kopec, to learn how people can begin their programming journey with Dart.



Q) On behalf of the Dart team, thanks for writing Dart for Absolute Beginners! So, how did you discover Dart?

David: Working in the startup world, I always try to keep abreast of exciting emerging technologies in the sphere of software development that may ease the lives of developers like myself. I first came across Dart in late 2012 while trying to get a consumer automotive web startup in LA off the ground. Dart was still in its early phases, but I was quickly enamored with its clean design and potential to ease Web development for both professionals and novices alike. I took a mental note and thought — this is something I need to come back to!

Q) What made you want to write a book about Dart?

David: I think when one is the solo author of a book about an emerging language/platform, more than anything else, you need to believe in its potential. I see Dart as an opportunity for a clean slate. It’s a fresh start incorporating all that we’ve learned about best practices for language design over the past 20 years. I see the industry spending a lot of time shoehorning older web technologies into places that they don’t necessarily fit well at scale. Dart is a better approach.

Clearly, I wanted to be a Dart advocate, because I truly believed that it’s a better way forward for the Web. The book was the natural offspring of my belief in Dart, desire to write a beginner’s book, and opportunity in my career time-wise to do it.

Q) Who should read the book? Who is the book for?

David: Dart for Absolute Beginners is truly designed for absolute beginners - individuals with no programming experience. It aims to be a broad introduction to programming, the Dart language, selected parts of the Dart platform, and the technologies behind the Web. In short, readers who want to learn Dart as a first programming language are the intended audience.

With that said, I have also received positive feedback from programmers with some experience that seek a Dart book with an eased learning curve.

Q) Why should people new to software development start with Dart?

David: Dart is a beautiful, clean, modern language, that comes with a batteries-included platform. Many people want to start their programming journey on the Web because of its immediacy and cross-platform compatibility. Yet, they end up having to tackle a hodgepodge of technologies, libraries, and frankly, a language, JavaScript, that has many inconsistencies.

Dart delivers all of the benefits of developing for the Web (immediacy, compatibility) but in an elegant, consistent package. New programmers don’t need to worry about language gotchas, because the language is clean and consistent. They don’t need to worry about what libraries they need for their project, because the Dart standard library is comprehensive. They don’t struggle with including additional functionality, because pub is so easy-to-use. They don’t need to worry about browser compatibility (too much) because the Dart team handles that for them as part of the unified platform. They don’t even need to think about which IDE/text editor to use because the platform comes with an easy-to-use one.

Another point worth mentioning, is that Dart includes modern object-oriented features that are nice transferable skills for when a new programmer wants to learn a second modern language like Java, Swift, or Ruby. Some of these advanced object-oriented features are sorely lacking in JavaScript. As a beginner, it’s nice to start in a place with your feet pointed towards the future.

Q) What makes Dart for Absolute Beginners special?

David: Dart for Absolute Beginners is the only book about Dart as a first programming language. All of the other books on the market assume at least a little bit of knowledge about another programming language. They are introductions to Dart, but not introductions to programming, Web technologies, and modern software development techniques for absolute beginners.

Beyond being an introduction to programming, Dart for Absolute Beginners also aims to be a broad introduction to modern Web software development techniques, in the sense that by the time the reader is done he or she will get a taste of version control with Git, unit testing, and even a basic understanding of HTTP. But my favorite feature is an included interview with the Dart project’s founders.

Q) How do you use Dart today?

David: I use Dart for client-side Web projects. I encourage consulting clients to have their projects built in Dart. I have not yet fully explored server-side Dart but it’s an area of future interest for me.

Q) What advice would you give to a developer learning Dart for the first time?

David: Beginning programmers often get frustrated by how far it is from Hello World to say making a graphical game. Don’t give up! Like anything else in life, programming takes time, practice, and dedication. Also, make sure you can walk before you attempt to run. I’ve seen beginners try to jump right into making a complicated Web app before they have mastered the basics of loops, data structures, and functions. That only leads to frustration. No matter what language you’re learning, the key is to have a solid foundation that you can build from. It’s not important to memorize all of the API calls in dart:html. You can always look those up. Memorization in programming isn’t especially helpful in the age of the search engine. Instead, beginners should work on building an understanding of language concepts.

Q) Where can developers follow you and your work?

David: My blog is Observational Hazard and I’m available for consulting projects through Oak Snow Consulting. You can also follow me on Twitter, G+, and GitHub.

Thanks David! Developers, new and experienced, can find Dart for Absolute Beginners at Amazon or Apress.

Monday, December 15, 2014

Enums and Async primitives in Dart

Support for enums, async, and deferred loading are now officially part of the 2nd revision of the Ecma-408 standard, the Dart Programming Language Specification. The second revision was approved last week at the Ecma General Assembly.


You can find more information about using the new features in our language tour on dartlang.org:

Enums

Enums help developers express clear intent with minimal code, and help tools catch potential bugs. Here is an example of an enumeration of form states:

    enum FormState { OPEN, INPROGRESS, CLOSED }

Tools can even warn developers if they omit an enum value from a switch statement, which helps identify potential bugs.



Async

Dart has always had strong support for asynchronous programming, with core library features such as Future and Stream. Now, with the new language primitives async and await, asynchronous code is much easier to read and write.

The following code is easy to read, because a developer can follow the logic, line by line. However, the lookUpVersion() function actually runs asynchronously!

checkVersion() async {
  var version = await lookUpVersion();
  if (version == expectedVersion) {
    // Do something.
  } else {
    // Do something else.
  }
}

Deferred loading

Users expect web applications to load extremely quickly. Dart's new deferred loading syntax helps a developer send minimal code to the client on the initial download, and load extra functionality on demand. This means that the user downloads only the code that they need to get started, resulting in faster load times.

Enjoy!

We are excited about these new language features and are working hard to provide full-fledged implementations of the new features in the Dart SDK as soon as possible. We look forward to your feedback on the new features.

Friday, November 28, 2014

Dart 1.8: library improvements and experimental support for enums

Would you like to try out Dart’s upcoming support for enums? In Dart Editor under Tools > Preferences > Experimental you can “Enable Enums Support” and start experimenting with code like:


With Dart 1.8, a number of library improvements have also landed. 
  • In dart:collection, SplayTree added toSet() method, and in dart:convert a JsonUtf8Encoder class was added. 
  • In dart:core, the following three things were added: 
    • New properties and constructors for RangeError
    • A new IndexError class - used by the RangeError.index constructor
    • Optional start and end arguments for the String.fromCharCodes constructor.
  • In dart:io we added support for the ALPN extension of the TLS secure networking protocol for Client and Server.
For a summary of these and others changes see the release notes. You can download Dart 1.8 from the Download Dart page. If you are running the Dart Editor, you can update by checking "About Dart Editor". Check out the Dart support page for information on getting help, filing issues, and contributing to the project.

Friday, November 7, 2014

Running Dart server applications on Google Cloud Platform

Today you can develop and deploy Dart server applications that run on the Google App Engine Managed VMs beta.

The productivity of the Dart language and libraries are a great fit for server applications. You get the competitive performance of the Dart VM while leveraging powerful tools like Observatory–all while easily sharing code with your browser application.

Now you can try Dart on Google App Engine, which lets you build and run applications on Google’s infrastructure. App Engine applications are easy to build, easy to maintain, and easy to scale as your traffic and data storage needs change. With App Engine, there are no servers for you to maintain. You simply upload your application and it’s ready to go.

Managed VMs extend App Engine to support user-defined custom runtimes. The Dart team is building on custom runtimes to allow you to easily develop and deploy Dart server applications that run on Google’s infrastructure.

Once you have set up your local development environment, you can quickly write and test your Dart server application using simulated App Engine Services–Datastore, Memcache, Logging, and more–on your development machine. A local admin interface gives you direct access to the services on the running instance. We’ve created several samples to get you started.

When you’re ready to deploy, App Engine gives you control over your application resources. You can also easily configure it to allow your application to automatically scale up and down in response to traffic. Once your site is live, you can monitor and manage your application using the browser-based Google Developers Console.

The Dart packages we are releasing today are beta, so we’d love your feedback. To participate in the discussion on running Dart on Managed VMs, and to stay informed with news and announcements, sign up for the Dart cloud Google Group. We are looking forward to your feedback so we can improve your experience with Dart and Google Cloud Platform.

To get started, visit dartlang.org/cloud.