Monday, July 6, 2009

Danger of being overly focused (to a skillset)

I started playing with XCode, Objective-C and iPhone Application Development recently (which was about 3 days ago).

Some background on my skillset first.

I started out learning Pascal and Foxpro, and then proceed to C++ with Visual C++. Along the way I picked up VB, and then Java. Then I worked with Java professional for about 3 years, and then out came C# (within that 3 years), which I then decided to make a jump for it, but ended up with VB.Net and Visual Studio for about a year. And then I decided that Java had a better career opportunity back then. So it was back to Java and Eclipse for another 2+ years.

And this is where I am now. Which is to say that I am strongly comfortable with Java and Eclipse (but seriously, Eclipse is an excellent IDE).

During the time I read up on Ruby and Python, but resisted developing with them, blaming the lack of an IDE with the quality of Eclipse.

And now that I want to try out iPhone Application Development, I had to pick up Objective-C and XCode.

I started reading up on both topics. And with every read, Objective-C felt like an excellent language. Named parameter was a big plus for me. Categories were a good way to slice up code into separate files (much like .Net's extension methods). Other than that, much was the same as old time (to me). XCode itself was a good tool, with code completion support (though I have yet to read anything on refactoring, and not much books talk about unit testing though they are available online).

And then came the time of actual usage. I was confident that with my experience in C++ I could tame that Objective-C beast. And the tool did seem good.

I was wrong. Not on the account of Objective-C. That was pretty easy. I am a firm believer that language syntax are simply decorations. And so I had concentrated on honing the more important skills of writing clean code, design patterns, building stronger foundation. But development still take a while, because I was so used to Java. Coding in Objective-C requires some mindset changes. Recognizing new symbols.

XCode was a much bigger killer. Code completion works, but code 'suggestion' was a different key. I had to retrain my instincts. I have yet to figure out unit testing, but probably will complain when it get working, citing it as different and weird compared to Eclipse (but that is definitely due to my overly used to Eclipse, not because of XCode). Checking for compilation errors was different and had to get used to. And looking at the logs while debugging was... well just wonder why I had to switch my view in XCode. Perhaps there is a different project layout view (I was sure I read something on it), and I should try that.

So why so much pain? I became overly reliant on a single tool and language. And that is definitely a very dangerous thing. Regardless if you read up on different tools or languages, if one does not actually try using them, they will not be able to operate under different environment. And as developers, we MUST be as flexible as possible. One can never know what tools one might use in the future of their career. (I am currently cursing on using Visual Studio in Windows XP VM on my Mac... GRRRR).

And after years of using Java, a garbage collecting language, I had to revert back to a non-garbage collected language. More care is put into each line, and there is always a wondering thought on if I should release the memory of something returned from a system call, or not if I am returning them as return arguments. It takes some getting used to.

I probably should have tried out Ruby and Python more often, and C++ too, with a variety of tools. Life would be better.

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.

Saturday, May 23, 2009

Where can Twitter get money?

Twitter has recently annouced that they might offer a premium twitter service at the end of the year. But before then, there were endless thoughts and advices on how to run twitter. How various company should buy twitter, why twitter should sell, and wonders on how long twitter will go down the deadpool.


Except seriously, twitter has nothing to be afraid about. Various attempts have been made to create alternative microblogging services, tools, and software, but they did not seem to gain the same amount of traction and adoption rate.

Twitter is an infrastructure. Messaging delivery infrastructure.

The rate of growth is unbeliverable fast. The ecosystem of tools and services around it is huge as well.

People are using it for real time news and search. Recently, if I have to find information, I use twitter search first before I even try google.

Companies are monitoring twitter for keywords to do direct sales and product support. In fact, they are more responsive than me sending them an email for support!

Imagine if twiiter goes bankrupt and into the deadpool. Imagine all the companies that will be affected.

Which is why all the alternatives to twitter keep coming up. And the advices to business models and selling to a rich company like microsoft or google.

People are afraid of losing such an important tool. And people do recognize its importance!
And so the investments come. People who are betting on a future with twitter. They might want direct paybacks on the long term. Or they might have interest in the twitter ecosystem. Or they might be using twitter and am convinced how it will help them in the long run.
That is an interesting growth/survival strategy.
Start with something free. Make it easy to use, and easy to create tools and services around it (the API). As long as it gains popularity with the netizens, and the ecosystem starts to grow, investments (or donations) will come.
But that's easier said than done I guess.

Sunday, May 17, 2009

iPhone game price drop, an unfairness to early buyers

As I begin writing about this, I realized that this applies to anything that is on sale. Whenever the price of a product drops after a person makes a purchase, he is attacked by a wave of emotions. Specifically of unfairness, or even worse, betrayal.

But let's restrict the topic to iPhone applications specifically.

I buy applications. Quite a few of them. Even thought some of them may be expensive by iPhone app standards (well maybe around 9.90?). But in most case I felt that they ate worthwhile productivity applications. That would be fine.

I monitor application released as well. When there is an application that comes out, and if I was interested enough, I would buy it immediately.

But I am now going to talk about games. Not all games have a lite version. And we all know how some review sites would hype up a release. And in most cases, you cannot decide if you like a game or otherwise until you try it out.

So I ended up buying some games on reviews, or by the reputation of the producer on other platforms.

And quite a few of them disappoints me.

To run salt onto my wound, the producer probably knows too. And to drive sales up, they drop the price. Example would be from 9.90 to 5.90. All this happening in the span of a month.

So where does that leaves the early buyers or loyal fans?

I can understand promotion price for maybe Christmas or other events. Buy a permanent price adjustment?

From now on, I'll probably wait for around 3-6 months before I get anything from itunes (unless there is a promotion of say 1.99 and below). I don't want to feel like being taken advantage of anymore.