4 ms·
The sample program on the Haxe main page demonstrates a complete misunderstanding of the value of dictionaries. Not exactly inspiring one to learn more. cl
by brianberns 12y ago
The sample program on the Haxe main page demonstrates a complete misunderstanding of the value of dictionaries. Not exactly inspiring one to learn more.
class Test {
static function main() {
var people = [
"Elizabeth" => "Programming",
"Joel" => "Design"
];
for (name in people.keys()) {
var job = people[name];
trace('$name does $job for a living!');
}
}
}
- jdonaldson 12y agoIt's a simple example, but it's showing a lot of nice things. The "people" instance is using anonymous syntax for a Map type. Haxe's Map types are actually abstract types: http://haxe.org/manual/types-abstract.html http://haxe.org/manual/types-abstract.html. I doubt many developers are familiar with this type of feature. For instance, here's a "packed array" implementation that lets me store an array of integers in a fraction of the space usually needed for a standard array type: https://github.com/jdonaldson/packhx https://github.com/jdonaldson/packhx Abstract types let me use the same api that standard arrays use (including array accessors), even if the underlying runtime implementation is completely different. The other nice things going on in the example is the simple for loop using an iterator, and the nice string interpolation. Granted, this is nothing super sophisticated, but it's great to have these same features across all the targets that Haxe supports.
- joneil 12y agoHaha, I was the one that wrote that example for the homepage. It was never meant to be a comment on the ideal data structures for different use cases. Rather it's just there to give developers a taste of the syntax: there's more semicolons and brackets than Python, less explicit typing than Java. If you have an example of a better code sample for introducing language syntax, I'd love to see it so I can learn from it.
- brianberns 12y agoMy point is that if you're going to iterate through the entire dictionary, there should be a way to get full key-value pairs, so you don't have to look up the value for each key. There's no need to change the entire example. Something like this: for ((name, job) in people) { trace('$name does $job for a living!'); }