Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Sunday, September 30, 2012

Dart Koans

The next week or so, I'm going to be limited in the amount of time I will have for some programming. I will hopefully still get some programming in but I will be limited in how much time and frequency I will have for it. Because of that, and the fact that I'm a little impatient, I've decided to share some information on my current project.

The project is Dart Koans. It is inspired, though not based on, a ruby project of a similar name: Ruby Koans. I completed the Ruby Koans when I was first learning Ruby, having come from other similar languages like Python as well as from JavaScript. The Koans helped a lot because I learn really well from hands-on coding. Additionally, while covering the basics, it does dive right in.

I felt that a similar approach to learning Dart would be a great contribution to the community. There are many programmers coming in from other languages who are comfortable with the basic concepts and don't need some of the background or theory involved with traditional tutorials. They're familiar with what a variable is, and just want to know how they're used in Dart. They're itching to write some code in Dart to see how it feels.

The Dart Koans are for people new to Dart, and comfortable on the CLI (currently it's not recommended to run from the Dart editor, as it's blocked by a couple of bugs.
1) Issue 4654 (Dart Editor should handle ANSI color output).
or
2) Issue 2789 (Provide a way to find out if stdout is connected to a terminal).

The idea behind Dart Koans is that you achieve enlightenment through failure. You start with many failing tests. And individually correct each test and re-run the program. With each run of the application you should get closer and closer to resolving all tests. Each test introduces a new concept of the Dart language or libraries. At the moment it is still very very early and only a small portion of the total tests are completed. Currently there are 55 tests. By the time this is completed I expect well over 300 or more. As each test fails it will provide the error, line and file to look at to correct the issue. Each test (using the unittest library) is accompanied by several comments which will provide information about the concept being introduced.

Due to the early development stage, the tutorial is currently very much in the preview stage and far from its completed form. However I intend to add more tests and areas as much as I can. I'm interested in any feedback or comments or concerns but please keep in mind things are very much subject to change. Current output is primarily for demonstration purposes and is most likely not the final result.

Because I will be updating very frequently I will not be making many blog posts about the projecct unless its regarding a significant milestone or involves any major changes to the project.

Friday, January 20, 2012

Not So Generic

I was working on a post on Generics in Dart, had a significant amount written yesterday but was running into a couple of bugs (bug reports were, for the most part, previously submitted). Coming back today and looking at my post and trying to pick up where I left off, I decided the best option, for your sake and mine, was to delete it. I had a mess of things jumping from one topic to another, code samples that had far too much fluff and useless elements that it was far from clean, concise and illuminating. So I admitted my mind wasn't as focused as it should have been and deleted the post entirely. It wouldn't serve much purpose to try and clean it up at all.

I've decided for the time being I'm going to leave the generics to Seth Ladd's most capable post: Generics in Dart. I highly recommend reading it and pay particular attention towards the end of the post to help avoid some 'gotchas'. He does a great job explaining covariance and keeping it simple at the same time. The only additional thing I will add is that not only can you use generics on the initialization of a variable but also in the declaration as a type. Doing so will really help, particularly the editor, to keep a close eye on what you are assigning or adding to a variable. The only example I will show is very brief: http://try.dartlang.org/s/lywo
main() {
  var list1 = ["One", "Two", "Three"];
  List list2 = new List();
  List list3 = ["One", "Two", "Three"];
  
  list1.add(4); // No warning because the type isn't specifically declared.
  list2.add(4); // generates a warning
  list3.add(4); // Generates a warning
}

Assuming you are not running in checked mode, all three cases will run properly. However, list2 and list3 will generate errors on the add lines indicating that int is not assignable to a string. The first case, list1 will quietly and happily accept 4 as being added to it, even though we initially specified that the variable of Dynamic type list1 is a List of type Strings. If running in checked mode, all three will fail.

Apart from that, I decided that over the weekend I'm going to start working on an introductory tutorial to Dart. Something for the programmer with little experience. Many of the resources I've seen have been geared towards those experienced with Java programming or heavy JavaScript users. I'm debating if I should go with just VM initially and get the foundations down or just DOM initially so they can get right into results. Because lets face it, when you first start as a programmer we're all about the results and making the computer do something cool rather than all the theory and foundations. However I believe I can offer that with the VM on a starting level.