FastIteratingStringMap: part 2

benchmark-v2-small

Some time ago I wrote a post about an idea, how StringMap could be implemented (for js target) to have ability to iterate fast. I continued to work in this direction, and finally idea evolved into nearly final implementation.

  1. Tests were added;
  2. Special iterators implementation for case when there is no data in the map;
  3. Benchmark code instantiate a specific class now (instead of using creator function), to give Haxe ability to optimize map usage and inline functions;
  4. Haxe 3.2 (from development branch) was used to compile benchmark;
  5. Another idea was tested (CachingKeysStringMap);
  6. Constant time complexity.

Continue reading

FAST iterators for StringMap

benchmark-small

StringMap is probably most used class in Haxe (I think only Array is used more often). Probably you never use it directly, rather you use Map<String, SomeType>, which use haxe.ds.StringMap under the hood.

Since it is used very often, it must be very fast. At least it should be… So let’s go a little deeper and look how haxe.ds.StringMap is implemented for javascript target.

Continue reading

Tricky unsafe cast is too tricky

Important: this article is written about Haxe 3.1.3. It works well in Haxe 3.2 🙂

Few days ago I wrote about eight things I don’t like in Haxe, and one of thing was tricky unsafe cast syntax:

(cast findViewById(R.id.myTextView):TextView).setText("Cool");

compared to safe cast:

cast(findViewById(R.id.myTextView), TextView).setText("Cool");

However I was wrong. This unsafe cast work fine only on dynamic targets, but on cpp it cause compilation error:

Continue reading

8 things I don’t like in Haxe

STOP right here. Before I say a few words of criticism about Haxe, you should know, that i REALLY like this language.

Btw, this post is pretty old, haxe was improved since I wrote it.
Feel free to read other posts 🙂
Top 3 (in my taste):

Ok, let’s continue.

I use many programming languages everyday, and Ruby Haxe is the most promising of them. Thanks to Haxe I can build my projects for web, for mobiles, build them as native applications. Comparing with JavaScript, Haxe has strict typing; comparing with C++, Haxe is MUCH easier to write. Enum-matching is fantastic thing! And last, but not least, Haxe allow me to write platform-specific code via untyped keyword (just like old good #ifdef in C / C++).

But there are several things that make programming in Haxe more complex and not so exciting. Maybe some of that things will be fixed in next versions of Haxe, while other things is by design and will not be fixed even in Haxe 4 / Haxe 5. Anyway, I still want to talk about them.

Continue reading

Setter with default getter + Actuate = problem

Let’s say you need to animate some custom property of object. And you choose to use Actuate as tweening library:

Actuate.tween(someObject, 1.0, { myOffsetX: 100 });

Moreover, you need to do some work when property updated, so you decide to create a setter:

public var myOffsetX(default, set):Int;

private function set_myOffsetX(value:Int):Int {
    if (value != myOffsetX) {
        myOffsetX = value;
        doSomeWork();
    }

    return value;
}

It works fine while you building it to flash, but stop working on html5 or native.

Continue reading