Friday, March 14, 2008

Token management

Its a weekend...last week was damn busy..and i was all occupied.
Its better now and i am just planning to chill all weekend - For now I am reading Heinz Kabutz on Java Concurrency, listening to "Simon & Garfunkel - The only living boy in New York". And Ofcourse I am composing this blog.
Here is something i learnt last week. Had written some methods sometime back and now was the time to move them to live environment.
I took sometime refactoring them, I discovered a stupid flaw in my design (it was no big deal).
The flaw was to do with tokens! Wellll i still use tokens for things for which i think xml would be an overkill- this was one such instance.
I wrote a method that would just take the string name and the token as arguments and return me tokens! simple as that - List getListOfTokens(String origString, String tokeniseOn).
Like any loose API- the method got abused!
it got called from all over the place with people using it for different tokens- well i must admit that was what the method was originally written for...
But if you have a parser that has token nesting - and uses this method it can be pretty nasty!
for eg- tommy;gina;Jovi, Bon;Sambora, Ritchie
Imagine if u used the method like the one above to quickly manage these, u would loose track easily if there are many calls to it. Imagine if token changes and someone decides to use ":" instead of , !
In my opinion if you ever decide to put together something thats to deal with tokens then consider having all your tokens together - like say contants declared in one place..
for eg:
FIRST_LEVEL_TOKEN=";";
SECOND_LEVEL_TOKEN=",";

This would definately ease managing tokens across project much easy.

No comments: