so here’s the story, i got an interview at a consulting firm. since i already passed the preliminary technological interview this time around i was told that the interview is going to be focused on object-oriented design. so, i met the interviewer and he gave me a problem for me to solve. here’s the initial problem.

“suppose we have a class of Animal. because this is Animal class it can have much variety of Animal in the future. but for starters, let say if we have four different animals: Cat, Dog, Horse, and an Elephant. now, these animals have some behaviors such as sleep, run and carry. the rule for implementing the behaviors is to prevent any duplication of code, copy-and-paste is not good. i have defined several behaviors to you, but there will be more additional behaviors in the future. here’s the specific behaviors for the animals. all animals will be able to sleep and use the same sleep function. all animals can run, but each animal runs differently. only Elephant and Horse can carry things. remember, because we may have gazillions of classes in the future, any additions should have minimal impact to the module. build me your design.”

Read the rest of this entry »

Mail Support in .Net

March 26, 2008

.Net doesn’t have a native supported API like Java do (JavaMail). So, it’s up to contributors to do the job. One of the highly recommended library was Indy Sockets from IndyProject. The library was once implemented for Delphi and right now are being ported to .Net. However, I found the design and the functionality is still lacking and on different level with JavaMail (I only looked at the CLR code and not the Delphi version). So, here’s one of the things that I want to do when I got the time: Is to write a .Net Mail API that can be comparable to JavaMail.

it’s been a while since I looked at stl. and this trip into stl and c++ native programming really brought me into senses once again. i built a simple project using stl, the program itself is very simple. i want to have a dictionary where entries can be looked-up using strings and the result is also in strings. only this time, i want it all to be in stl. i know that we can use map to do this, but to brush up my skills and to see the effect of composability, i used a list combined with a pair in the structure. it’s a one liner very easy. or so i thought.

 the problem arises when i tried to use find to get an entry. suddenly all hell break loose. all those cryptic stl error messages pouring down in my error window and it forced me to decrypt the messages one by one. the problem seems to originate from the inavailability of string operator==. so, i figured that the string operator== needs to be defined. no sweat. bool operator== ( const string& left, const string& right )… that should do it. but no, the error just wont get away. okay… maybe the pair operator== needs to be defined: bool operator== ( const pair<string, string>& left, const pair<string,string>& right )… no sweat.

again, i tried to recompile it, but the error just refuses to go away. what happened? doh… i tried various thing. i changed the pair to a pair of ints, it went smooth. i tried various combinations, i tried putting the find logic itself out from the funtion and put it in the source, but to no effect. after i tried for a while, i thought it is the time to try google. so i did. I surfed through the forums, but c’mon no forum will discuss this kind of problem specifically right? instead, i found a hint. written in a forum is a small advice: ‘put it inside the std namespace’. then it struck me! damn, i declared the operators outside the namespace! i put it inside the namespace cage, and… voila! everything works fine.

things that i learn:
1. mind the namespace.
2. decrypt stl messages by means of substitution, eg: basic_string<char, chartraits> = string
3. don’t blame the library. 99.99% of mistake is of your own doing (as i have written before)
4. respect the semantics.

about no.4, i have given a thought why string doesn’t have operator== defined. i dont have the full answer, but i guess it might be because of performance problem. or, because of semantic problem.


client for 2channel (2ch)

February 7, 2008

 so, because of the super-ugly appearance of 2channel and because it is so unintuitive to always refresh your browser to keep up with the thread in there, i thought of writing a client for it. well, of course there are other clients that is available for it as my friends have told me once. but, then after looking for a while, i know that there’s client that’s based on .Net. furthermore, there’s none for WPF. so, i thought it might be nice if i can make one.

 however, looking at how 2channel works, i began to wonder if there is a special API for this to work. i mean, if there are clients outthere, it’s not too much hoping somekind of ‘backdoor’ like webservice or rss feed available, isn’t it? my search returns me nothing. oh well, maybe it is unofficial or seldom discussed API or something, so i looked up at 2ch free open source clients and pop the source code open on my VS…. to my suprise, they’re all parsing the html page and building their request strings manually (doh). it seems that 2ch doesnt have an API from which a client can hook-up to. plzzzzzz give us an API.

 btw here’s the clients that i’ve been talking about:

Before you say that, think carefully. Years before, I’ve been into this large project. I think we have like ten projects running simultenuously with hundreds (if it was not a thousand) of people in the factory. They’d have like software engineers, programmers, hardwares people, managers, even the top executives running on site. So, it’s pretty big. I’m in the software department, obviously, as a junior developer (they called me that eventhough I think I’m the most skilled one in my team. we’re only a team of 4). Upon entering the project, I quickly realized that we are running on a very specialized platform where facilities that we used to have were non existant. Even the debuggers need some special hardware enhancements and special softwares to run. Compiling and running the code would take you about 2 hours at minimum. So, there were lots of frustration and we have to make sure that when we write code, we wrote it right the first time, or else we’ll just wasting time. The code base were so big that it is impossible to inspect or understand all of it. Not only that, the program were written in C, but without any means of structural designs. So we have a couple of this BIG main functions that says something like:

function A (){
 while ( 1 ) {
   switch ( globalVar1 ) {
      case 1: …
      case 2: …

And we got some parallelism that some functions/files/modules run on different processes. We access memory deliberately that if I missed a number, such as I write 1 instead of 2, it will crash my module completely without any noticeable faults. So, you can see that its not a pretty sight.

Along came a bug that is so frustrating and unfortunately it was assigned to me. Still quite shocked about the program structures and the scarce of utilities I tried to find the source of the bug. After a while I got so frustrated that I concluded that the fault must be in the library that our module were using. Confident with the conclusion I told my manager. This is what he says:

Manager (M): You sure of this
I: Yes
M: You have checked the codes
I: Yes
M: You tested it?
I: Of course…
M: You have proof?
I: Ummm,… well I’ve seen it running
M: You have direct proof?
I: Err,… not really
M: How can you tell that its the library fault?
I: A guess…
M: Look, we’re engineers, not economic analysts. There’s only 1 or 0, true or false. Give me some proof before you came into conclusion
I: … yes sir
M: Check it again

So I get back to my console and check the codes one again, line by line, code by code, files by files. AND there it is. A bug that I wrote (doh). So I fixed it and came back to my manager.

I: Sorry sir, I’ve found the bug and fixed it.
M: You sure?
I: Yes, I’ve tested it and I have proof
M: Good. In my experience, 99.9% of bugs came from the developer and not from the library, so don’t give me that piece of crap next time
I: … I understand. I’m sorry sir.

Lesson learned. Don’t ever make the assumption that the library at fault at first time. 99.9% of bugs came from the developer not the library. That words were deeply engraved in me even right now. Happy coding!

… a machine that talks

September 20, 2007

Look here. It’s already a pretty common subject, so I don’t think it will surprises anyone. But, anyway I haven’t wrote anything on AI (or in this case Cognitive Intelligence). It’s a pretty cool thing. And I suspect in not so distant future we’ll have these kind of softwares running on our desktops that capable to do at least limited cognitive recognitions. I like the idea of the computer itself actively trying to resolve the relevance of the subject and context that was presented by mining data into the local system itself and the net if possible. However, there must be some basic commands that are needed to start a conversation. Things like opening file or running an application should be available from the start. Thus, a basic set of instructions and words are required. And then there is the thing with memory, SILVIA that was mentioned in the articles seems to be have a short time memory so that it can remember contexts, however, I personally think that a more long-term memory is also needed. The problem with most AI is, AFAIK, that they need a learning process. People doesn’t talk the same with one another, there are styles. And SILVIA, for one, have to be able to learn this styles also if it want to be able to communicate smoothly with the user. False positives at first are inevitables, and SILVIA systems have to be able to comprehend this by reconfirming to users. Users might be frustrated at first, but after it learns, SILVIA shouldn’t produce much false positives. It really like raising a child. To be able to adapt means that SILVIA needs to store informations about the users styles and preferencs, ‘way of saying something’, these memories are required to be stored in somekind of memory. And that’s where the long-term memory came. The long term memory could also be a place for SILVIA to store things that maybe specific for each users. I see lots of potential in the research for these kind of software and very eager to have a good  ‘assistant’ in my desktop. Next step after Cognitive Recognition, is of course, to make them more intelligent. So that, for instance, I can say ‘drive me to office’ to my car and it’ll move on it’s own. But again, DARPA is already on this capability, so maybe we’ll soon to have intelligent car that can be instructed by natural language in the near future. Cheers.