one reason, you get type checking when you declare the handlers

handlers["some string"] : contents of 'some string' arent checked

handlers[STATE_A | STTE_B] : Compile error : STTE_B is not declared.

the other reasons are habit and familiarity :)

Im used to seeing and working with code for handling states that uses all that bitwise stuff because of working in other languages where its more common (e.g. c++). If you feel more comfortable with string based solutions thats all good, but like i said, the one point where they differ is that the compiler doesnt check the contents of a string, so a typo can go un-noticed.

thanks,

Martin


Andreas Weber wrote:
Nice!
And I was determined not to post again, but at a certain stage my mental
block irresistibly kicked in again:
why ingeniously bit-wise encode the combinations just to later decode them
for better readabilty?

Why not drop this altogether as we won't do any encoding:
        static var STATE_A:Number = 1; //  1 << 0

Define the handlers like
        handlers = {};// or type it/ make it a class
        handlers["STATE_A"] = Delegate.create(this,handleAOnly);
        // etc.

And finally:

     public function handleUpdate(a:Object,b:Object,c:Object,d:Object)
     {
        state = 'STATE_';
        if(a.selected){ state += 'A'};
        if(b.selected){ state += 'B'};
        // etc.

        handlers[state]();
     }

What's the benefit of encoding/decoding numbers? Please enlighten me!

Cheers!
--------------
Andreas Weber
motiondraw.com

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to