Home > java > How to improve your programming skills

How to improve your programming skills

Ever visit sites like topcoder.com and solve a problem or two ? No ? You should and do so regularly. It will help find tune your programming / design skills. This is because solving the problems requires going though the following thought process

  1. Understanding the problem.
  2. Thinking up a solution that covers all use cases.
  3. Executing your thought process through code.
  4. Testing.

Now as simple as that sounds, it is not so easy to get right. Especially when you are competing with thousands of fellow coders for time. And when time is a constrain you usually select the first solution that comes to your head, which might not necessarily be the best. So there is that risk of your code timing out even if it is following the right logic. I would love to delve into a problem right about now and throw in some examples and illustration, but you get the point.

When the thought process that we follow is not well defined and we lose focus, it often leads to buggy code. Don’t believe me ? Here are some bugs I caught in a code base on a recent project.

Bug 1

Bug 2

Bug 3

There were more bugs identified after development than what is listed here. But what I wanted to highlight was that the problem was introduced into the system due to lack of focus and clarity of thought. Well, more often than not anyway. Other times the bug sneaks into the system because the number of test cases to test a method were not sufficient.

Have a look at this google research blog post about broken binary search and merge sort algorithms for example. They pretty much have the same bug as the date calculation bug that I highlighted in a different post. We are all prone to creating bugs, but we can minimize the number of ones we introduce into the system.

So what have I learned from introducing bugs so far ?

  1. As long as you keep your skills sharp and practice solving problems, the number of bugs you introduce will reduce. I try to visit sites like topcoder.com or codingbat.com whenever I find the time.
  2. Learning from other’s mistakes and best practices can save you tons of time.
  3. Try not to cram in your work within X hours. This tends to focus the effort on finishing the code on time instead of writing it neat and bug free.

As always its easier said than done. But hey, its never too late eh ? As for finding the bugs in the first place…

  1. Use a tool like FindBugs after you are done coding. You will be surprised at how many problems turn up.
  2. Try to maintain a code coverage of at least 80 %. Tools like Emma can help you track this.





Categories: java Tags: , ,
  1. June 9th, 2010 at 21:28 | #1

    CodingBat seems a bit lame, you can’t include even things from apache-commons it seems.

    TopCoder seems interesting, but putting money into the mix makes it a bit tricky. Starting or especially contributing to open-source efforts is a good learning experience, too.

    FindBugs is great, too bad it’s so hard to write custom detectors.

  1. No trackbacks yet.