Thursday, 13 June 2013

Be brave! Delete code!

Most developers have fear of changing code that they don't know. Adding new code is OK for everyone - even in large functions or large classes. That of course leads to mess in code and big ball of mud syndrome.

The main problem is that only a small fraction of developers actively try to understand what others have written before. Is this lazines? Or lack of confidence? Or maybe deadlines are tight and writing new features is more important that code refactoring or fixing bugs?

My advice is: don't be one of these guys. Don't do just what is assigned to you. Spend a little bit of time looking around for possible improvements. If you see a big method - split it. If some flow is hard to understand - improve it. If naming is bad - change it. And one of most important things - be brave and delete dead code. If it will be needed again (it probably won't) - you have source control systems (if not - change company).

Now imagine if everybody in your team have spend some time every week on improving exiting code, from beginning of project. I know it is a bit of investment of time for the project/company, but remember: changing clean code is much easier that changing big ball of mud. It will pay off.

Tuesday, 4 June 2013

Source access

Access to source is the key for developer's happiness.

Imagine that you must use some closed third party library and one thing just don't work. You do everything as documentation says (if there is documentation) or as internet says. And you don't have access to source code. What to do in that case? If you are lucky, and this is Java or .NET, you can use decompiler and hope that code was not obfuscated. If you are unlucky and library is pure binary - good luck with that!

With Open Source this is just easy - you can look at source code, get a version with symbols (or build your own) and use debugger to find what is wrong. Here is example from last days: Kadu was crashing when OTR conversation was initiated from it. Debugger only showed that there was bug somewhere inside otrl_message_sending function. I grabbed source code, got a quick look and found a bug that only occurred when specific parameter value was passed to it. Fix was ready in no more than 10 minutes - no need for stress!

PS. This bug was already fixed at the begining of this year in libotr 4.0.1 that will be released soon.