March 15, 2011
Posted by on
I recently heard an interesting quote from Ghandi:
Whatever you do will be insignificant, but it is very important that you do it.
Of course on a micro-scale, your actions might seem important and may have an influence on the near future. But on a macro-scale, your actions and everything you do as an individual, will not change a lot in the universe and will be just lost in time.
But then why should it be important to do something? Why should we even begin doing something, if we know for sure it will not be something that will change the world?
I will try to explain why by describing how this applies to software development. An average programmer doesn’t write that much code. Most of his time he is debugging, testing or reading. Writing new code might take about 10% of his time. Altering existing code might take even more than 10% of his time.
When a developer changes existing code, he has a goal: make the code do what it’s supposed to do. But this could be done in a quick & dirty way: just fix the code with a minimum amount of effort (because it will be just an insignificant change after all, isn’t it?). Even if a quick fix does the job and the developer might even get appreciation from his not-so-clever-looking-into-code manager, this simply isn’t enough.
You, as a professional developer, should do the following additional tasks when fixing a bug or every time you look over existing code:
- refactor: change code in such a way that it is easier to maintain and more understandable. Rewrite the code in a better, cleaner way, keeping the functionality intact. Refactor to patterns. Break dependencies. Every time you identify some part of the code which might be refactored and you think “it’s not worth the trouble” or “I don’t have time for this”, you should Refactor It Anyway.
- rewrite: if you see some piece of code that may be written in a better, faster or shorter way, rewrite it. Even if it just saves you a line of code or spares you a local variable, you should Rewrite It Anyway.
- rename: properly rename methods, variables, properties, classes, interfaces. Rename everything that doesn’t reveal its purpose at the very first moment you read it. If you see a variable named counter and you think “oh, I understand now what it counts” after reading some lines of code, you should rename it. Even if a variable is needed in just a line of code, you should Rename It Anyway.
- comment: write comments whenever you write code that isn’t trivial. Always ask yourself: if someone else reads this code, will it be understandable? Comment methods, but also classes and interfaces. A method like GetSerialNumber() might not need a comment, but a SerialNumberDecryptor class might need one. Even if it takes you just a second to understand a piece of code, you should Comment It Anyway.
- cleanup:be vigilant! Don’t leave ugly looking code behind you. Remove unused code, remove unused namespaces or unused variables, remove test files. Properly indent code. Make sure you respect coding conventions. Don’t live with broken windows. Even if you notice some misplaced spaces in some code, Cleanup It Anyway.
Everyone of this actions are insignificant compared to the whole project. But it’s important that you Do Them Anyway!