By Developers, For Developers

Historical errata for Dart for Hipsters

PDF PgPaper PgTypeDescriptionFixed onComments
196TYPO

In the ajax_populate_list(container) function:

graphicNovelsTemplate(list) should be:

graphic_novels_template(list)

This causes Dart Editor to error, anyway.

2012-08-10Yikes. I wasn't following my own coding conventions in the first chapter :( \n \nThe camel-case version is the one that follows the conventions. Fixed in multiple places.
55ERROR

The description of privacy (around page 55) is wrong. It states that super or sub-classes don’t have access to private variables.
That’s only true if they live in different libraries. Conceptually the leading “_” of any identifier is replaced by ““. Code that lives in the same library as the field (or any other variable) will thus be able to access the field. If the code comes from a different library its ”” will expand to a different name and thus make it impossible to access the field from the other library.

2012-08-12Thanks for explanation. It seemed like an arbitrary rule when I first ran into it. This seems much more reasonable. \n \nStill, since subclasses can very well get refactored into separate libraries, I think I would still recommend to never attempt to access subclass / superclass private instance variables -- even in the same library. Sounds like a recipe for hard to track down bugs in the future. \n
13ERROR

3.3 Booleans

In the 3 ternary expressions, like in:
greeting = name ? “Howdy $name” : “Howdy”;

the first parts are assignments, but they should be comparisons,like:
greeting == name ? …

The greeting = name ? version gives an exception:

Unhandled exception:
type ‘Null’ is not a subtype of type ‘bool’ of ‘boolean expression’.

2013-01-22This still (more or less) works for me--at least on try.dartlang.org: http://try.dartlang.org/s/kYRJ \n \nI also tried it in Dartium, where it still works as well. \n \nWhere are you seeing this?
15,16SUGGEST

3.5 Lists:

The statements:
muppets.some((muppet) {
return muppet.startsWith(‘C’);
});
// true

and the equivalent every and filter statement
should better be replaced with the more elegant forms:

muppets.some( (muppet) => muppet.startsWith(‘C’) ); // true
muppets.every( (muppet) => muppet.startsWith(‘C’) ); // false
muppets.filter( (muppet) => muppet.startsWith(‘C’) ); // [‘Count’]

2013-01-28Agree 100%, but I don't introduce the compact function form until chapter 3. Since this is in chapter 2, I am reluctant to push too much at people. \n \nI'll talk this over with my editor, though. It really is much nicer. \n \n--- \nI think we'll stick with it as-is. It is not *that* horrible and it keeps the narrative a little simpler to introduce the hash-rocket in the next chapter. \n \nStill agree 100% that it's much nicer :)
17ERROR

3.6 Dates
The statement:
var mar = new Date.fromString(‘2012-03-01 Z-0500’);

gives an
Unhandled exception:
Illegal argument(s): 2012-03-01 Z-0500

2012-08-10Interesting. This works in try.dartlang.org (http://try.dartlang.org/s/LRdJ), but in the VM I'm seeing the same failure. It seems as though the VM parser does not like the timezone. \n \nI'll update the text with a non-timezone example. Thanks!
22ERROR

fib_printer(i) {
print(“Fib($i): ” + fib(i));
}
gives no method + exception
should now be:

fib_printer(i) {
print(“Fib($i): ${fib(i)}” );
}
or even better:
fib_printer(i) => print(“Fib($i): ${fib(i)}” );

2012-08-10Right you are - thanks!
66ERROR

8.7 Constructors - Factory constructors

The code:
class PrettyName {
factory PrettyName(name) {
return “Pretty $name”;
}
}

does not work; it gives the following exception:

Unhandled exception:
type ‘String’ is not a subtype of type ‘PrettyName’ of ‘function result’.

2013-01-22Interesting. It works in try.dartlang.org: http://try.dartlang.org/s/5yJJ \n \n \nThis also works for me in recent build of Dartium. I do not get any errors and am able to build factories.
87ERROR

10.3 Core Dart libraries

The following does not compile
(cannot find referenced source):
#import(‘html’);
#import(‘json’);

It should of course be:
#import(‘dart:html’);
#import(‘dart:json’);

2012-08-12
83ERROR

10.1 # Source
In pretty_print.dart, the line:
if (thing is List) print(INDENT + Strings.join(thing, ‘, ’));
must be replaced by:
if (thing is List) print(‘$INDENT ${Strings.join(thing, ’, ‘)}’);

2012-08-12
85ERROR

In the text the + method is used in various places to concatenate strings; this is no longer valid and should be replaced with string interpolations.

These are some of the occurrences:
i) code of _graphic_novels_template.dart (chapter 1)
ii) print(“Fib($i): ” + fib(i)); in § 4.1 Anonymous functions
iii) § 9.2 #import
print(“Elapsed time: ” + timer.elapsedInMs() + “ms”);
should be:
print(‘Elapsed time: ${timer.elapsedInMs()} ms’);

2012-08-12Yup. I've grepped through the code and I *think* I have all of these (including the one that you identified here).
86TYPO

i)
Note: Chrome is smart enough to load #source() and #import() files only once, no
matter how many different places they might be referenced.

instead of Chrome you should mention the Dart VM

ii) in the list of libraries, dom is still mentioned
but this library is now deprecated

2012-08-12Good catch, thanks!
14ERROR

Map’s hasKey method does not exist, should be containsKey method, on page 14 and page 15.

eg:
if (!options.hasKey(‘age’)) {

2012-12-01Agreed. Fixed in source.
21ERROR

fib(3) // => 3
should be
fib(3) // => 2

2012-12-01Good catch, thanks. Fixed in source.
16ERROR

“The Set class is a List …” should be “The Set class is a Collection …”.

“The Queue is a List that can be manipulated at the beginning.” should be “The Queue is a Collection that can be manipulated at both ends.”

2012-12-01Agreed. Fixed in source.
28ERROR

document.
query(‘ul#people-list’).
queryAll(‘li’).
each((li) {
li.addClass(‘highlight’);
});

should be

document.
query(‘ul#people-list’).
queryAll(‘li’).
forEach((li) {
li.classes.add(‘highlight’);
});

2012-12-01Agreed. I would prefer `each`, but they are sticking with `forEach` to retain similarity with JS. Fixed in source.
29SUGGEST

For create new element, Dart now support create the element directly. eg: new DivElement()

2012-12-01Good point. I added a mention in source.
30ERROR

NodeList implement List. So

document.
query(‘#content’).
nodes.
append(gallery);

should be

document.
query(‘#content’).
nodes.
add(gallery);

2012-12-01Agreed. Fixed in source.
31SUGGEST

Dart has supported method cascade. So if api doesn’t return this, it also can chainable call.

document.
query(‘blockquote’).
classes.
remove(‘subdued’);

document.
query(‘blockquote’).
classes.
add(‘highlighted’);

can write this:

document.
query(‘blockquote’).
classes..
remove(‘subdued’)..
add(‘highlighted’);

2013-01-22
32SUGGEST

In note paragraph, dart:htmlimpl library has removed from sdk.

2012-12-01Removed the sidebar entirely from source.
45SUGGEST

Dart’s new getter syntax should remove the braces. This should revise all the getter method.

2013-01-22
35SUGGEST

For “Currently, there are no command-line switches that alter the behavior”, currently dart2js has -o/-c/-h command-line options.

2012-12-03Yup, fixed in source.
65ERROR

For the Note paragraph, Dart now support initialization expression at the field declared. for example:

class ComicsModel {
ModelEvents on = new new ModelEvents();
}

see the article “Simplify your constructors and top-level variables” on news.dartlang.org

2013-01-22
66ERROR

For the Important paragraph, about the call superclass’s constructor.

From the Dart language tour:

By default, a constructor in a subclass will call the superclass’s default constructor. If no default (zero-argument) constructor is defined in the superclass, you must manually call a constructor in the superclass.

So, in here, because ComicBook’s supercalss ComicsModel does not define a zero-argument default constructor, so ComicBook must manually call super constructor.

2013-01-22
101ERROR

For test chapter.
1)Now unittest is in Dart SDK, and no need to export from svn.

two import method:
File style,#import(‘path-to-dart/pkg/unittest/unitest.dart’); or
Package style, #import(‘package:unittest/unittest.dart’);

2)In addition, dartest has removed from Dart. So DARTest and run test in browser does not work.

3)asyncTest is deprecated, it should be replaced by expectAsyncX.

4)The Expect class in dart:core is deprecated, and expect() should be used instead. eg, expect(2 + 2, equals(5));

2013-01-22
122ERROR

localStorage is now implement Map, and getItem/setItem method does not exist. eg:

var json = window.localStorage.getItem(‘Comic Books’)

should be

var json = window.localStorage[‘Comic Books’]

And window.localStorage.setItem

should be

window.localStorage[‘Comic Books’] = JSON.stringify(comics);

2012-12-02Good catch. Fixed in source.
125ERROR

if (comic_book[‘title’] 'Sandmn') { comic_book['title'] ‘Sandman’;
}

should be

if (comic_book[‘title’] == ‘Sandmn’) {
comic_book[‘title’] = ‘Sandman’;
}

the second == should be =

2012-12-01D'oh! Fixed in source.
127TYPO

String message = “$method: ${model.url}”;
the sentence reduplicate

2012-12-01Agreed. Fixed in source.
128SUGGEST

CanvasRenderingContext or CanvasRenderingContext2D ?

I suggest use :
CanvasRenderingContext2D context = canvas.getContext(‘2d’);

2012-12-02Yah, it should be the 2D version. The superclass version has none of the methods used in the example code, so the Dart analyzer / compile checks would fail. Fixed in source.
122ERROR

oneDay = new Duration(1)

should be

oneDay = new Duration(days:1)

Because Dart now use new named optional parameters syntax({}) and Duration now use this style, the parameter
name are not optional. See the article “BREAKING CHANGES: Duration, RegExp, Uri.fromComponents” on news.dartlang.org.

I also suggest add an introduction for named optional params and positional optional params on chapter 3.3

2012-12-02Agreed. Fixed in source. Added a note-to-self to update 3.3.
46ERROR

In the Hipster Collections section 6.2 you define the collection with the two stream controllers _onLoad and _onAdd and the models list and then go on to say that you declared only two instance variables “on” and “models”. This disconnect is repeated a few times throughout the chapter.

2014-05-01Tsk. That was part of the conversion from Dart pre-1.0 to 1.0/1.1. I really thought I had caught all of those, but I do seem to have missed some in this chapter. Thanks for the catch -- will fix shortly.... \n \nMaybe not “shortly,” but this is fixed in source. Chapter 6 has been mostly rewritten to avoid this trouble.
91TYPO

The first sentence has the last 2 words transposed. It reads: “JavaScript has been around for years eighteen.”

2014-01-27
95TYPO

Section 10.4 Packaging with “pub”, second sentence states: “As we saw in Chapter 12, Testing Dart, on page 111, it is capable of resolving and installing dependencies”. We haven’t yet seen that chapter, and I’m not quite sure what “Testing Dart” has to do with resolving and installing dependencies.

2014-01-27Dang. Hazards of working with the book in parts, I suppose. The testing chapter installed stuff via pub, including resolving some dependencies. Had it come first in the book, that would have made more sense. \n \nBut really, there is no need for the cross-reference, so I've simply removed it. Thanks!
39TYPO

Hello! I found issue in the code on Github first, but now I found it in the book. Please, check my PR for fixes github[dot]com/eee-c/dart-comics/pull/4.

Short description: JS can’t use Dart interpolation and script starts working before document body is loaded trying to append to document.body which is null.

Thanks!

2014-01-27
84SUGGEST

Need to be consistent with IterableBase and Collection. See forums.pragprog.com/forums/254/topics/12488.

2014-06-04I have fixed this in the source, but am leaning open for the time being to double-check that IterableBase is sufficiently explained.
19ERROR

Starting here, but throughout the rest of the book, query() should probably be replaced with querySelector() (see groups.google.com/a/dartlang.org/forum/#!msg/misc/dJnz6DbyPbs/eDe5BwAm140J)

2014-05-13Added a note in the book that query is not really deprecated. For more info see: http://japhr.blogspot.com/2014/05/query-is-not-deprecated-in-dart.html
47ERROR

The discussion under DOM Ready confused me a little because I just used dart2js to make some JavaScript and through it in a normal script tag. When you do that, the rules change. I realize you recommend using the loader script, but even then the recommendation is to put the script tags at the end to avoid these issues (see www.dartlang.org/articles/embedding-in-html/). Perhaps this is a gotcha worth mentioning?

2014-06-09I really didn't want to do this previously, but your suggestion spurred a nicer transition into the next chapter (Compiling to JavaScript). \n \nSo, much thanks! \n
59ERROR

The first two paragraphs after the first code example, that begin, “We cheat in our implementation of the forEach() method…” don’t seem to have anything to do with the code shown.

2014-06-02Yup, that's either old text referring to new code or new text referring to old code. Either way it's a mess. But fixed now.
63ERROR

The lead up to the save() code talks about how the code needs to POST on create, but PUT on update. Then the method hardcodes a POST. Oops.

2014-06-02Wow. Good catch. I must have read this section a dozen times and never noticed that...
64ERROR

The event description at the top of this page doesn’t match the actual code (on the previous page).

2014-06-02Yup, this is fixed in book source now.
78ERROR

The text above the first code example and the actual code disagree about which interface is implemented.

2014-06-04
93ERROR

The `extends IterableBase`/`implements Collection` confusion is back on this page.

2014-06-04
94TYPO

This paragraph doesn’t make sense: “Back in the HipsterCollection superclass, we declare modelMaker() as abstract (by omitting the method body). create() to use this method.”

2014-06-04Yikes! Something when wrong back in p3.0 and no one caught it until this :-\\ \n \nFixed in source.
115TYPO

I think this sentence is in need of a verb, “It is worth pointing out that, because of how Dart manages libraries, setting HipsterSync.sync in our main.dart file, like so:”

2014-06-04Bah. I tried stretching a sentence across multiple code examples. I stopped doing that now. \n \nFixed in source.
130ERROR

I think the second code block should use handleException() instead of catchError(). (If not, the text above is wrong.)

2014-06-06The text above was wrong. It should be catchError: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-async.Future#id_catchError \n \nI grep'd through the rest of the text / code and all handleException references are now gone.
57SUGGEST

Need to remove event mentions from chapter 7. They are no longer used in chapter 6.

2014-06-05

Categories: