19 May 2008

Vectors in Flash Player 10

Last week Adobe released a beta version of Flash Player 10. Many exciting new features: 3D effects, a replacement for those clunky old TextField objects (finally!), improvements to the drawing API (which interestingly mirror some work I'd done for my puppet package), access to low-level audio functionality, local file access (no more stupid scripts to bounce files off a server!), etc. One of the most exciting things for me, though, is the addition of vectors.

The word "vector" has a lot of meanings, but in computer science and some branches of mathematics, it basically means "list". Of course, we already have Array objects for creating lists in ActionScript. Indeed, vectors are very similar to arrays, but with one very important difference: the elements must be of a specified type.

Here's an illustration of the difference:
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.display.Sprite;

var list:Array = [];
list.push(1);
list.push("A String");
list.push(new Object());
list.push(new MovieClip());
list.push(new Shape());
list.push(new Sprite());
trace(list.join(", "));
// Output:
// 1, A String, [object Object], [object MovieClip], [object Shape], [object Sprite]

Note that the elements of the array are of all kinds of different types: a number, a string, a plain vanilla object, and several display objects. But suppose we changed list from an array to a vector with elements of the type DisplayObject:
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.display.Sprite;

var list:Vector.<DisplayObject> = new Vector.<DisplayObject>();
list.push(1); // throws TypeError
list.push("A String"); // throws TypeError
list.push(new Object()); // throws TypeError
list.push(new MovieClip());
list.push(new Shape());
list.push(new Sprite());

Now the elements must be of a particular type, and attempting to add objects of any other type will throw an error.

Note the syntax for specifying the type of the vector's elements. This is actually an early introduction of parameterized classes, which are going to be part of the ECMAScript 4.0 standard. (They're already features of languages such as Java.) I was surprised that they'd include an ES4 feature so early, but it seems to be implemented only for vectors. I was unable to make my own parameterized classes in the alpha version of Flash CS4. Also, since Vector is a final class, you can't make subclasses, parameterized or not.

Even so, it'll be great to finally have some kind of type-safe collection. I can't tell you how many times I've had to make my own specialized, type-safe classes for this kind of thing.

Vectors will also improve performance, since the compiler can optimize code for vectors of integers, etc. When initializing a vector, you can also fix its length, allowing for further optimization. For example, to store a 3D spatial position as a list of exactly 3 numbers (x, y, and z coordinates), you can use:
var point3D:Vector.<Number> = new Vector.<Number>(3, true);


Can't wait to start using these....

07 May 2008

What happens when you mix invertebrate sex, homemade crafts, and a European actress?

Answer: The Greatest Thing Ever

ISPN3 Meeting: Abstract Deadline

There's only one week left to submit abstracts for the Third Meeting of the International Society for Phylogenetic Nomenclature! (I just submitted two, one for a talk and one for a poster.) The deadline is May 15, which is also the deadline for early registration.

Once again, some important information:
When? 2008 July 21–23
Where? Dalhousie University, Halifax, Nova Scotia, Canada
How much does it cost? $190 (CAD*) if you register by May 15
What if I'm a student? $90 (CAD*) if you register by May 15
Where do I register? At the Protist 2008 website. (Be sure to select "I am registering for ISPN"—unless you're a protistologist, of course.)
How do I submit abstracts? Follow the instructions here, but send the document to harold [dot] bryant [at] gov [dot] sk [dot] ca and use one of these keywords:
  • theory of phylogenetic nomenclature
  • history and development of phylogenetic nomenclature
  • definition of taxon names
  • other (specify).
I'm a U.S. citizen. Do I need a passport? Yes.
Where can I find more information? In the Second Circular.

The last meeting (Yale 2006) was great and hopefully this one will be even better!

* Canadian and U.S. dollars are worth about the same these days.

27 April 2008

DRAGABOK

Over the years I've accumulated quite a lot of doodles, sketches, etc. They're filling up some boxes in my office closet. So I thought I'd start scanning them and posting one per day to a new blog.

I give you:

(The title is Old Norse for "drawing book"—or close enough, anyway.)

Enjoy!

17 April 2008

Comments on the Flex Best Coding Practices

Adobe recently published preliminary coding guidelines for people making contributions to the Flex framework (mx packages). Here's the link:



Although it's specifically meant for the Flex project, the vast majority of their guidelines are applicable to ActionScript 3.0 code in general. Overall, I really like their direction. But I thought I'd take some time to comment on what I don't like or find questionable.

1. Acronyms

When using acronyms in code, the programmer faces a dilemma: convert the case to whatever is appropriate for the context, or leave them all in caps? They opt for the latter, and usually this is fine. However, names that use two acronyms can suffer from ambiguity, as in their hypothetical example loadCSSURL (which some programmers would prefer be rendered loadCssUrl).

Personally, I think there's no good solution here, so I just go with their approach. But I recognize that this approach has problems. As they say about loadCSSURL, "[T]ry to avoid such names."

2. Package names should always be nouns or gerunds

Actually, guys, a gerund is a noun. You're thinking of participles, which are verbs and, in English, look exactly like gerunds. (Gerund: "Walking is fun." Participle: "I was walking.")

Anyway, I don't see why this should be so. I've named a lot of packages after verbs, myself. Is it really that bad to name a package of things that draw something draw as opposed to drawers or drawing?

3. Start interface names with "I"

I've gone back and forth on this one and have finally decided that I actually hate it. Suppose I start out making something an abstract class and then later decide it should be an interface (or vice versa)? Why should I have to rename it when, to external code, nothing has changed? In most cases, external code shouldn't care whether an entity is an interface or a class (the obvious exception being when external code is expected to implement the interface).

I tend to use adjective for interfaces when possible, but often I just use plain old nouns. What's the harm?

4. Brackets on their own lines

They never explicitly recommend this, but all the examples show it. To illustrate what I mean, they recommend this:
function foo():void
{
if (test())
{
doSomething();
doSomethingElse();
}
else
{
doAnotherThing();
}
}
Over this:
function foo():void {
if (test()) {
doSomething();
doSomethingElse();
} else {
doAnotherThing();
}
}


Now I've heard people swear by the former, saying it makes blocks of code much easier to spot. But to me, it seems like a huge waste of space. I can only see so many lines at once, and if half of them are brackets, I'm going to have to be paging up and down an awful lot. Besides, I've been using cradled brackets for over a decade and I don't have any problems spotting blocks.

That said, I've never tried the other way, so I reserve final judgment until I give it a fair chance.

5. Event handler names

The recommend the form eventNameHandler. I like the older ActionScript convention onEventName. Not only is it more succinct, but it has the added benefit of placing all your handlers together when you sort methods alphabetically.

6. Postfix vs. prefix operators

They recommend postfix over prefix operators, despite the fact that prefix operators are generally faster. This completely baffles me. If this:
for (var i:int = 0; i < n; ++i) {
trace(i);
}
...is faster than this:
for (var i:int = 0; i < n; i++) {
trace(i);
}
... then why on Earth would you ever use the latter? It's not like one is more readable than the other. They're equally legible, and one is faster—no contest.

7. Single-statement if blocks

They recommend leaving brackets off. Personally, I prefer to always use brackets—it's more visually cohesive, and it makes things easier when you later realize you do need another statement in there, after all.




By this time it probably sounds like I hate their ideas, but actually, these are the only ones (and I follow that first one, anyway). Everything else is great and much of it had me going, "Yes! Preach it!"

This is something every ActionScript coder should read. Like me, you may not agree on every detail, but overall, it's an excellent guide.

16 April 2008

The Third Meeting of the ISPN: Second Circular

The second circular for the Third Meeting of the International Society for Phylogenetic Nomenclature has been posted on the ISPN's website.

The Third Meeting of the International Society for Phylogenetic Nomenclature will be held in Halifax, Nova Scotia, at Dalhousie University, from July 21 to July 23, 2008. This meeting is an opportunity to discuss topics that pertain directly or indirectly to phylogenetic nomenclature in general, as well as the International Code of Phylogenetic Nomenclature (PhyloCode) and the Companion Volume in particular. In addition to providing a forum to contribute oral and poster presentations, this meeting will also include plenary talks by invited guest speakers. This meeting is organized in close collaboration with the International Society of Protistologists (ISOP) and the International Society for Evolutionary Protistology, which are hosting the joint Protist 2008 meeting, at the same venue, from July 21 to July 26, 2008.


The deadline for early registration and for abstract submissions is May 15.
(I better go get working on my submission[s].)

12 March 2008

More Tininess From the Malay Archipelago

I've been blogging on nothing but code lately, so here's a "quick" paleo-post.

"Hobbits": Primitives or Pinheads?

The anthropological world was shocked several years ago by the discovery of a relatively recent pygmy species of stem-human, popularly dubbed "hobbits" and more technically dubbed Homo floresiensis (Brown et al. 2004). Known from subfossil remains of several individuals from the island of Flores (Morwood, Brown et al. 2004), including one nearly complete skeleton including the skull (the holotype specimen), these people stood barely over a meter in height, shorter than any modern pygmy humans. They survived at least until 13,000 years before present (Morwood, Soejono et al. 2004), and, judging from the one skull, they had extremely small brains for such late-surviving Homo (380 cc—we average around 1400 cc and even Australopithecus africanus averaged in the 400s). They had other primitive features as well, such as chinless jaws, a low twist in the forearm bones (Ibid.), robust leg bones (Ibid.), a chimp-like wrist (Tocheri et al. 2007), and some features of the teeth.

But not everyone agrees that the Floresian "hobbits" are a separate species. Various researchers have proposed that they are, in fact, pygmy Homo sapiens and that at least some individuals, including the holotype, have a pathological condition that includes microcephaly, a.k.a. "pinheadedness" (Martin et al. 2006, Jacob et al. 2006). After all, at least some of the supposedly diagnostic features, such as chinlessness, are present in some members of our own species (Jacob et al. 2006). But others insist that there are genuine primitive features in the Floresian specimens that cannot be explained by microcephaly or dwarfism (Falk et al. 2005, Falk et al. 2006, Argue et al. 2006).

A New Discovery

Until recently, the Floresians' size distinguished them from H. sapiens. But that was before this week's publication (Berger et al. 2008; open access) of some very recent (1400 to 2900 years B.P.) pygmy/dwarf fossils from Palau. More work needs to be done to free these fossils from the limestone they were found in, but they seem to be Homo sapiens proper, high-domed skulls and all. What's really interesting is that, like the Floresian "hobbits", the Palauans are smaller than any living population of H. sapiens. But unlike the "hobbit" holotype, their cranial capacity is not abnormally low.

Berger et al. note that the Palau specimens have some supposedly "primitive" features that may in fact be related to size, such as proportionally large teeth (megadontia) and chinless mandibles. The authors don't firmly ally themselves with either camp, but note that at least some of the supposed diagnostic features of H. floresiensis are probably phylogenetically uninformative, merely being results of dwarfism.

Thoughts

Personally, while I'm no expert in any the fields involved, I find the arguments that the Floresians are pathological, pygmy H. sapiens unconvincing. For one thing, people afflicted with the proposed diseases don't actually look like the "hobbits" except in having small brains. For another, asymmetry that was ascribed to pathology seems more likely to me to be a preservational artifact. Look at just about any fossil skull face-on—most of them are asymmetrical.

But more damning are the limb characters, which no known pathology can explain. (Did they have some kind of "ape-itis" in addition to microcephaly?) Fact is, I think that if H. floresiensis were 130,000 years old instead of 13,000, nobody would even contest the idea that they weren't H. sapiens. And morphology deserves more weight than chronology in matters of systematics.

References
  • Argue, D., D. Donlon, C. Groves and R. Wright (2006 October 4). Homo floresiensis: microcephalic, pygmoid, Australopithecus, or Homo? Journal of Human Evolution 51(4):360–374. doi:10.1016/j.jhevol.2006.04.013
  • Berger, L. R., S. E. Churchill, B. De Klerk and R. L. Quinn (2008 March 12). Small-bodied humans from Palau, Micronesia. PLoS ONE 3(3):e1780. doi:10.1371/journal.pone.0001780
  • Brown, P., T. Sutkina, M. J. Morwood, R. P. Soejono, Jatmiko, E. Wayhu Saptomo and Rokus Awe Due. (2004 October 28). A new small-bodied hominin from the Late Pleistocene of Flores, Indonesia. Nature 431:1055–1061. doi:10.1038/nature02999
  • Falk, D., C. Hildebolt, K. Smith, M. J. Morwood, T. Sutkina, P. Brown, Jatmiko, E. Wayhu Saptomo, B. Brunsden and F. Prior (2005 April 8). The brain of LB1, Homo floresiensis. Science 308(5719):242–245. doi:10.1126/science.1109727
  • Falk, D., C. Hildebolt, K. Smith, M. J. Morwood, T. Sutkina, P. Brown, Jatmiko, E. Wayhu Saptomo, B. Brunsden and F. Prior (2006 May 19). Response to comment on "The brain of LB1, Homo floresiensis". Science 312(5776):999. doi:10.1126/science.1124972
  • Jacob, T. E., Indriati, R. P. Soejono, K. Hsü, D. W. Frayer, R. B. Eckhardt, A. J. Kuperavage, A. Thorne and M. Hennenberg (2006 September 5). Pygmoid Australomelanesian Homo sapiens skeletal remains from Liang Bua, Flores: population affinities and pathological abnormalities. Proceedings of the National Academy of Sciences of the United States of America 103(36):13421–13426. doi:10.1073/pnas.0605563103
  • Martin, R. D., A. M. MacLarnon, J. L. Philips, L. Dussubieux, P. R. Williams and W. B. Dobyns (2006 May 19). Comment on "The brain of LB1, Homo floresiensis". Science 312(5776):999. doi:10.1126/science.1121144
  • Morwood, M. J., P. Brown, Jatmiko, T. Sutkina, E. Wahyu Saptomo, K. E. Westaway, Rokus Awe Due, R. G. Roberts, T. Maeda, S. Wasisto and T. Djubiantono (2005 October 13). Further evidence for small-bodied hominins from the Late Plesitocene of Flores, Indonesia. Nature 437:1012–1017. doi:10.1038/nature04022
  • Morwood, M. J., R. P. Soejono, R. G. Roberts, T. Sutkina, C. S. M. Turney, K. E. Westaway, W. J. Rink, J.-x. Zhao, G. D. van den Bergh, Rokus Awe Due, D. R. Hobbs, M. W. Moore, M. I. Bird and L. K. Fifield (2004 October 28). Archaeology and age of a new hominin from Flores in eastern Indonesia. Nature 431:1087–1091. doi:10.1038/nature02956
  • Tocheri, M. W., C. M. Orr, S. G. Larson, T. Sutikna, Jatmiko, E. Wahyu Saptomo, Rokus Awe Due, T. Djubiantono, M. J. Morwood and W. L. Jungers (2007 September 21). The primitive wrist of Homo floresiensis and its implications for hominin evolution. Science 317(5845):1743–1745. doi:10.1126/science.1147143