I'm usually quite proud of my code. If I'm not, I keep polishing it. When I review code of my guys, one of the things I insist of is to have the person's name on his code. Like on Dexter Horton Building.
If the guy says: "but all I did here is just to add this one little function".
"Well," I say to him, "so add your name above the function".
If the guy says: "but all I did was to fix this line. I didn't really added any new line of code".
"Well," I say to him, "so add your name above the line that you fixed, with a date and explanation of the fix".
But if the guy says: "hmmm, I'm not sure I'd like to put my name here. I'm not sure it works so well". Then I jump and say "haha! this is exactly why I insist on having your name there. Not initials. Not your nick name. A name that we can trace back when you will be a big manager at IBM, so you better don't leave any bug there."
The building above is real. I took this picture myself (I won't let you know where it's located. If you're curious you would probably google it.) I use this picture when I talk about code review and my insistence on having the developer's name on his or her code. Alex from mistralzonline, already documented this picture as part of his talk on present and represent, at his blog "On Everything And Nothing In Particular".
Saturday, February 28, 2009
Be proud of your code!
Thursday, January 29, 2009
The risks of redundant code (or - Less is More)
One of the preferred refactoring methods of my choice is deleting redundant code.
I separate between excessive code and redundant code:
1. Redundant code is code that never runs:
- Unreachable code
- Unused classes, interfaces and methods
- Commented-out code
- Code that looks wrong, then you understand that it is indeed wrong, but is being lucky enough not to be called
- Code that deals with cases that cannot happen
- Code that deals with cases that could happen in the past, but now cannot
- Code that is there for future cases, which are not occuring yet (and may be added sometime)
2. Excessive code is code that runs, but can be reorganized into less lines of code:
- Unnecessary abstractions, unneeded levels of delegations
- Copy-Paste that can be moved to methods, inheritance, templates
Both are bad and should be treated. But the first category, redundant code, is much riskier. The main risk of redundant code is that it looks innocent and useful, but it doesn't really work and it is never tested. In many cases you assume that there is some value in this code, so you keep it around, maybe it will become useful sometime. Well, most probably it will become useful by creating new bugs when you accidentally use it. Remember: this code was never really tested, just being there, so familiar, part of your code, does not make it something that works. And in many cases it confuses you, as you believe that a feature is already written, because the code is there, you only need to pass another value or take some code out of a comment. But this code was not maintained or tested for ages, if at all! How can you rely on it? Why keep it there in the first place?
My recommendation usually is to be very cautious with code that never ran and is just lying there, as it may be lying and not doing what it supposed to do.
Keeping unnecessary code requires you also to maintain these lines of code that you don't really need. Again, I say - get rid of it.
Thursday, January 8, 2009
Generic Software Mission Statement
Following my previous post on the subject, I created the following generic mission statement:
Produce quality code, on time, for the success of the company.
Yes, I know, it's VERY GENERIC, but as a general mission statement for software groups it's quite good.
The problem with a more specific mission statement is that it may miss the responsibility of some of your employees. I had a few years ago a small group dealing with projects for customer applications. In one of our business group talks, the business group manager threw at the entire group that the goal for the team in the following quarter was to achieve sales target of 1M$.
The problem was that it was a group of programmers, not sales people, and achieving sales target was not part of our responsibility. The manager was just pumping down to us his own target (probably adding 25%, just to increase our motivation). The results of this talk was horrible, people were going around thinking how to bring 1M$, instead of doing their programming tasks. It scared some and it totally ruined the motivation of most, who usually do not relate their code to money. Code is art, relating it to money makes it dirty. Instead of speaking of money it was much better to speak about features, projects and deadlines. Even setting for a programming team a target of number of customer projects to achieve is wrong. Mission and targets shall be focused on the responsibility area of the team. It's the manager's responsibility to hide all the rest.