Code Improvement is Never Costly

Let’s talk about more about code improvement. Some people seem to think that code improvement has a high associated cost. I think it only has a high cost if we’re not very good at it.

R U doin it rong?

I’ve been writing lately in response to people who seem to think you can go faster by doing work that is less good. Probably at some high level of internal quality, polishing doesn’t pay off. I think if you’ll look at the code around you, though, you won’t find any of that over-polished code near by.

We have all been faced with code that is not as good as it might be. There are two issues: recognizing that there is a problem, and figuring out what to do about the problem. Both of these issues are skill-related.

From beginning programmer …
Expressive Names

An unskilled programmer may not realize that naming her variables pig, cow, horsie, and doggie is not a good idea. She does not know how to give them meaningful names because she has not yet learned how to create code that carries meaning. (I am not making this up. I knew this person.) This programmer will notice over time that she has to figure out over and over again what “mousie” means in her program. There will come a day when someone asking “What does that variable stand for” will get an answer. At that moment, if they say “let’s call it that,” she’ll take a step forward in skill.

A programmer of such low skill might focus entirely on giving things meaningful names. That will go a long way in improving the code, and it isn’t very hard to do. It doesn’t take much time to do and it pays off essentially instantly.

To intermediate…
Duplication

A programmer of somewhat higher skill might learn to notice duplication of simple kinds, such as rape and paste feature implementations. There will come a day when they will say “I have to change this in five places now,” and if there’s someone there to explain to the programmer what a function, subroutine, or method is, he’ll take a step forward in skill. It doesn’t take much time to do and it pays off essentially instantly.

To expert…
Does a change look costly? Look to your skills.

At every level of skill, there are changes that are easy to spot and easy to fix, that pay off essentially instantly. Clear code works sooner and is easier to enhance. It doesn’t take massive efforts to write code clearly, nor to make it a little more clear than it was.

Clean code skills, from the very simplest to the most complex, do not take much time, and therefore pay off very soon.

When a team wants to take enough time to clean something up that they feel the need to ask permission, it is a clear sign that they do not know how to solve the problem incrementally. This is an explicit statement that they do not have the skill they need to deal with the issue.

It may still pay off to make the changes, because they are hard (for these individuals) and maybe focusing on them will give them a better chance of success. However, I’m coming to think more and more that the answer should always be “No. But you can have tomorrow morning to start. Do that, check it in, and then let’s talk again.”

6 Responses to “Code Improvement is Never Costly”

Krishna

February 4, 2009

3:26 pm

permalink

Ron, I think you are making a wrong assumption about the people you are responding to. Many programmers involved in these kind of discussions write good code and work in companies that produce reasonably good code. They are beyond problems of expressive names and code duplication.

And if you accept that, the question is: Do you agree that there is a level of code quality beyond which there are diminshing returns to further improvement? If so, what is it in your opinion? If not, when do we determine how to ship software?

jeffries

February 4, 2009

4:09 pm

permalink

On the contrary, Krishna. My point is that code improvement done commensurately with one’s skills, is never costly, whether you are beginner, intermediate, or expert.

As to your second paragraph, I believe I addressed that in the first paragraph of the article.

Sebastian Kuebeck

February 5, 2009

2:52 am

permalink

I think there is a confusion here between “code quality” and “coding rules”. They are not the same. For example: removing duplication improves quality. Adhering to a rule indicating that you must name all value objects with the suffix “VO” does not. In other words: Just adding new rules – how silly they may be – does not necessarily improve quality. That means using static code checkers, turning all rules on and forcing people to code in such a way that not a single warning must appear has no positive impact on quality. On the contrary: people will get distracted from implementing “real” quality in an attempt to adhere to arbitrary rules.
So there is a distinction between “real” quality and “percieved” quality as a result of oversimplification of the problem and it’s only “real” quality that should be permanently improved.

jeffries

February 5, 2009

9:43 am

permalink

Sebastian, as far as I can determine, I have never in my life written about coding rules, nor recommended using static code checkers, nor suggested forcing people to do anything.

I would prefer comments that are a bit closer to the topic in the future.

Thanks.

Sebastian Kuebeck

February 5, 2009

11:48 am

permalink

Sorry Ron, it seemed to me that Krishna implied something in that direction but I may be wrong. All I wanted to say is that people should concentrate introducing real quality by doing what you suggested in your post and not get distracted by things that sometimes pretend to improve quality but do not improve it in practice. However, I didn’t claim or at least I did not mean to claim that you recommended the things you mention in your last comment.

AgileMan

February 7, 2009

4:46 pm

permalink

Sometimes it can come down to a simple question of pride. Some developers see their current job as merely a stepping down to somewhere else (often in management, they hope), and therefore don’t necessarily perceive any value in either writing well-structured algorithm or cleaning up bits of code as they go. The best developers I’ve worked with, on the other hand, are the ones who think that any code worth writing is worth doing right, and they take pride in their work no matter how long they stay in one place. They also understand that it NEVER takes longer to do something well, if you include the clean-up time that inevitably is required, and usually at the worst possible time.

Recent Articles

Events & Classes

  • No events.