RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • TURTED
  • xosofox?
  •  

    A TURTED based real-time thing that I’m proud of…

    August 1st, 2011

    I recently finished a nice little example of how to use real-time data for an exciting and equally relaxing view:

    Blocker Champ Real Time


    http://reloaded.karopapier.de/blocker

    What’s that?
    It shows a list of players and the number of games where it is their turn.
    As soon as they make a move, they are moved to the new position with a nice animation.

    Interestingly enough, the hardest part was the JQuery/UI animation stuff.
    Since it already is based on the components that are soon to become the TURTED project the real time events were already there to be intercepted and used.

    So, if you feel stressed, just sit back, relax and watch the squares move – the ZEN of Karopapier


    JS Performance: Numbered Array vs Associative Array

    February 22nd, 2011

    In JS, you sometimtes have to keep track of lists. Usernames, sessions, available Pictures ,…
    And often, you have to add and delete some of them.

    So, how do you handle these lists? There are basically two options:

    a) Good old numbered Array
    b) Associative Array, key/value store

    Examples?

    var users=[];
    users[0]=”Adam”;
    users[1]=”Bob”;
    users[2]=”Claire”;

    users={};
    users['Adam']=”Adam”;
    users['Bob']=”Bob”;
    users['Claire']=”Claire”;

    Both have their advantages and disadvantages.
    An array keeps the order, you have numbered keys. However, deleting or finding an element requires you to walk through the array.

    So, the question to me was: How about performance? How big is the difference?

    Long story short:
    In case you do not care about the order and will only have unique keys, use an associative array!
    To add a value:
    assoArray[key]=value;
    To get a value:
    var myVal=assoArray[key];
    To delete a key/value:
    delete(assoArray[key]);

    This is easy and performs much better. At least in my quickly hacked, unoptimised test you can find here: Simple test html
    If you think I did something wrong, please enlighten me.