Monday, June 29, 2009

Finding an Identity on the Internet is a painful activity

I recently did something which I had actually refused to do for a long while.

I changed my msn nick from ., which I had used it since I got the msn account since... erm.. probably 2000 or so? But of course, I am still refusing to do frequent status updates, but somehow I get the feeling I would be giving in to that too, as I am twittering frequently already.

Why the sudden change? Quite simply, a rebranding exercise of my own brand.

It is really a VERY PAINFUL activity. It was not just the msn nick change.

First, I got my own domain name, kentlai.name (actually I got a few more, but .name is good enough). Next, I set up google apps standard edition on it. And then I have to start the migration of my blog and email accounts to the domain!

I am keeping the older blog and email accounts, but I had to forward my emails, as well as perform domain redirection to the new domain. That was not so bad. But then this meant that potentially there are 'two' of me on the internet. Both of them are me! It *could* cause confusion.

And of course, next involve grabbing username from services. I was lucky that I used my name as my twitter id. I managed to grab my name for the facebook vanity user url (though I was tormented between using my name as a single word, or separate it with a dot). I registered my username on a bunch of other services too.

But there are still some services where my username is not my name, but rather other forms. And I am wondering if I should start afresh for all of them and register a new one, or simply ignore them. For now, I'm probably taking a 'register if using' approach. If I am not going to use it, it might mean I never will. So I'll leave it for now.

But why the rebranding?

Because I need to let people know of my activities. And which of those activities belong to me. And reduce the possibility of impersonation.

We are in a connected world. Dangerous, and very real. Anything you say or do will be recorded in the internet, forever. And especially for us techies, we really have to protect our presence. We have to recognize that it is virtually (or nearly) impossible to remain 100% anonymous in the Internet. So, if we cannot beat them, join them!

I write articles (well used to), try to participant in forum discussions, and tweet. I try to engage in activities that I view would add value to myself, as I try to advance my career as a software developer/consultant.

The internet is increasingly becoming useful in job hunts, and heat hunting. Back when I was conducting or involve in interviews, I would google about the candidate, to get a feel of what his skills are. If there are no activities at all, I would usually start him off with a negative points. This is harsh, I agree, but I do have a reason.

If a person is interested in new technology, the same person would experiment around. And with experimentations, he would definitely hit problems that he cannot solve. At times, a simple google would solve it, but at others, he would not be able to find any information around on it. And that is where the person would seek help in a community forum (or stackoverflow now).

And of course, if he managed to have a smooth sailing, he should be rather knowledgeable on the product. He should be helping out on these forums too.

But of course, the face to face interview is still important, and the negativity of not having an online presence is not that heavy.

In the more advanced cases, the same person might have published articles. By reading them, I get a feel on how good a person is.

And if I am in a company that hunts talent, I probably would go to stackoverflow and choose a highly reputable user, or code project on someone who has published articles with the skill sets we require.

I am sure that I am not along in such thoughts, and that means that someone out there is hunting, and having a consolidated and online presence makes it easier for that person to hunt ME.

And a name sure spells out a person character. I look at my older hotmail and gmail email account names, and I go, "Boy was I childish".

I need something that spells that I am proud and confident of myself. And hence the name changes.

I would have had lesser problems if I had stick to it initially.

Monday, June 22, 2009

Stop anticipating requirements

As developers, we want an easier life. We worry and fear of unstable client requirements. We think of any possible ideas the client might come up with, and implement hooks for them in our current code (as long as they are not too tough, and even that is relative to a developer's skill).

Half the time, we are right, and we felt good about saving ourselves a lot of hell by putting in the hooks early.

The other half, the requirements never come. But we still felt good because we WILL be saving ourselves a lot of hell by putting in the hooks early.

But in general? The extensions and hooks we introduced made the system more complex. Code does not read that naturally, hidden within implementations of Template Pattern, nested one within another. The runtime structure of an application is so remotely different from the static structure of an application (class diagrams), that documentation no longer seem to be useful. In fact, they seem to be talking about totally different applications! The growing unnecessary hooks only add to more documentation, which seemed to scare every other developer away except yourself. And we wonder why.

But what could be worse? Well, that the requirements for a new feature came. And it is totally in conflict with the hook we planned. Well, we could argue that the hook was not well designed, and some change would be necessary, and then we could wait for the 'real' requirements to come. So for now, we add a hook to the hook, happy that we have added even more flexibility. And while we are at it, we thought of another possible client requirement. So we add another hook too.

And the story goes on. Hooks on hooks on hooks. on hooks. Half of them probably would never be used.

So what exactly went wrong? Obviously, the problem is us.

We tried to act like we are the client. Except we are not. We are probably the worse candidate to act like the client, since in most cases we are developing for a problem domain of which we are neither expert, nor even remotely familiar with.

Which is why as developers, we should always keep our solution simple. A simple solution is a flexible solution. Add hooks only if the actual client requirement comes. The value added service we provide here is faster delivery of solution, instead of a monolith and extensible solution but would require months to add new features.

Remember, in most cases the clients are the domain experts, not us. They may not always know what they want, but they do know what they do day-to-day. Spend time with them, understand their need. Do not give in to their desires. And do not give them something that they do not need.

Tuesday, June 16, 2009

Twitter tool that people should fear

This is definitely an old and outdated post on twitter, but seriously, I am starting to be very amazed, and at the same time, afraid of Twitter's immerse potential.

First off, it is really an unmoderated tool. In the sense that any topic goes. Nothing is blocked. Only suspect bot/spam accounts are terminated. But otherwise, anything goes.

Second, it is real time. Seriously. Want the latest news? Want the latest 'review' of a product, shop, place? Just run it through twitter search. You get the tweets people have on that particular topic you want, in reverse chronological order. And it will very likely to be more accurate than a site review of the same topic done, say, 6 months ago. For a software product, 6 months can involve many different iterations of software release.

What does this imply? Quite simply, that twitter is a force that no one can ignore anymore. Nowadays, if I am to buy a new software, book, or want to find out on a particular technology, I do a twitter search first. See what the others are talking about or feeling about it. As mentioned above, this is definitely a more accurate voice than a website review, which could be either outdated, or even worse, be biased because it has an invested interest into seeing the product spread, or just simply under pressure to do a favorable review.

Two more examples. I was having problem with a product, and I tweeted about it. Almost within a day, the product support tweeted back to help me. Same for my collegue, who was trying to contact a product for additional support and help via email, but did not get a reply in days. He tweeted about it, and they got back to him within hours. These companies know, that ignoring twitter, and they are ignoring the voices of the community, which affect their reputation, and thus their income.

I do wish that it would spread to beyond software and internet related news. Just recently, I had a very bad experience of customer service at a local shop. My first instinct was to actually tweet about it. Of course, I could be the one in a million who had the bad luck to be served by a bad customer service personnel. I could report it to her manager too. But in many cases, the manager does not take any actions. Or worse, in some cases, the managers themselves are rude. I am not asking to be serve as a king, but when I asked in a nice tone about something you sell, the least you could reply was in a nice tone about it, or even a simple 'I'm sorry I do not know' would do. If twitter could one day become so universal that everyone look to it as a source of authority and information, and could help shape and influence a shop's reputation and revenue, the shop could become a better place.

Of course, we then run into the risk of sabotages and esponiage. That would be a problem I am unsure of how to solve. Perhaps I am overly naive, but I would imagine that if one do evil to rise to the top, retribution would come one form or another. Of course, I could be very wrong.

But that is not the point of this post. The point is, twitter is very powerful. It is creeping into, and definitely affecting my decision making in many cases. On one hand, I am fearful that it becomes part of the decision making of everyone. But on the other, it provides a very loud user voice and is an excellent feedback channel.

And then there is a political aspect. Just look at the recent obama election last year. The attack on CNET on its failure to cover iran protests and elections. The china media blackout of the tian an men anniversary. Even government should not neglect the power of twitter as a media.

Next, I would not be surprised if the Singapore government would call for a moderation of the Internet again, especially on tweets. I do hope they can participate in it more actively in a positive manner, and not view it as a threat.

Monday, June 8, 2009

Towards Better Code: No side effects, shorter methods, exit early, and log every invocations

Recall earlier that I had mentioned that I learnt through logs of existing program/framework.

It's weird, but I cannot emphasize enough about the importance and need to log.

I have been using a rather new approach to logging. Well, not exactly to logging, but a new approach combining logging and coding style.

First off, I keep my methods short. For example, given the following algorithm:

public void login(final String username, final String password) {
  // authenticate
  // check if user container is active
  // check if user is active
}

It will most likely evolve into the following code:

public void login(final String username, final String password) {
  authenticate(username, password);
  verifyUserContainerIsActive(username);
  verifyUserIsActive(username);
}
void authenticate(final String username, final String password) {
  final boolean valid = checkUserCredentials(username, password);
  if (!valid) throw new AuthenticationException();
}
void verifyUserContainerIsActive(final String username) {
  final Container container = getUserContainer(username);
  if (container.isInactive()) throw new UserContainerInactiveException();
}
void verifyUserIsActive(final String username) {
  final User user = getUser(username);
  if (user.isInactive()) throw new UserInactiveException();
}

That's just a rough idea. Basically, each method is composed of many more methods, which serve to describe what each step do. Benefits? Eliminate the need to comment complicated algorithms. Comments run the highest risk of being out of sync with the actual code intent.

Also, notice the use of exceptions in the inner methods. I had started out with an alternative idea, that the inner methods would return true/false values, which would. It basically create the following nasty code block:

public void login(final String username, final String password) {
  if (isValidCredentials(username, password)) {
    if (isUserContainerIsActive(username)) {
      if (isUserIsActive(username)) return;
      throw new UserInactiveException();
    }
    throw new UserContainerInactiveException();
  }
  throw new AuthenticationException();
}

Of course, the better way is as follows:

public void login(final String username, final String password) {
  if (isNotValidCredentials(username, password)) throw new AuthenticationException();
  if (isUserContainerNotIsActive(username)) throw new UserContainerInactiveException();
  if (isUserIsNotActive(username)) throw new UserInactiveException();
}

Personally, I still felt that my first example up there produce a much more readable version of the algorithm, which communicates the intent much better.

But the basic idea/rule here is, exit early. What is most important is to communicate the basic intent of the code. The other possible cases are, well, exceptions (pun intended), and should not clutter the original intent of the code.

And finally, on to logging.

Now, I log all entry and exit of a method, as well as method arguments and method return values. Ideally this should be done with AOP, but I am not doing that yet.

What benefit does this logging bring me?

I can actually, from tracing the method entry logs, form a very clear view of how a request pass through the entire system. An example of the above log might be as follows:

enter: login {username:kentlai, password:xxx}
enter: authenticate {username:kentlai, password:xxx}
exit: authenticate
enter: verifyUserContainerIsActive {username: kentlai}
exit: verifyUserContainerIsActive
enter: verifyUserIsActive
exception caught: UserInactiveException

With shorter methods, logging every method invocations, I can trace the flow very accurately. Sure, there is an increase in the size of logs, but the return in such investment is easier debugging. Without even hooking up to the debugger.

With the logged method arguments, and knowing which method is causing a problem (from the logs), I can actually write a quick unit test to fix any potential problem found.

But there is one last magic elixer in this combination. No side effects.

Basically, each class should not have mutable state. The only mutable state should be from external storage (eg. database). And if a function need to use any values from such storage, they should, themselves be encapsulated into methods of their own, with the return values logged.

Why? This allow you to put together a complete picture, the context and environment of which a method was executed under. When every variable becomes known and can be supplied once again to a method during unit testing, a method can be guaranteed to work consistently and constantly as expected, which allows for more robust code.

Funny it took me so long to realize such principals.