Hey Developer, the product you create is your code

by Mark Nijhof, in Improvement Craftsmanship | Friday, July 03, 2009 | 3 comments
Many of you (yes you) have the weird notion that the functionality you create is actually the product you deliver to your stakeholder, and that is where you are wrong! Sure the needed functionality and behavior is the reason why you are programming, al do some developers don’t need a reason to code, we call this behavior YAGNI.

So if the functionality and behavior is not the product you deliver, than what is it?

It is your CODE.

And you know what? I need to be able to give your code to any other developer and they should be able to just pick it up and start changing and extending it. This means that by definition it is important that your code is readable and understandable; and no this does not mean readable and understandable to you.

Readable and understandable eh? So I’ll just add comments to the code to explain my intent, that should do it. Wrong again, if you feel the need to add comments to your code to explain what is going on then that is an obvious sign that there is something wrong with the way you wrote it. Make your code explain it self, that way it won’t be out of date when you change it.

Descriptive naming

The first step to make your code readable and understandable is to use descriptive names for all your classes, methods, properties and variables. Don’t shorten your names, make them complete. Yes this means that you will have to type a little bit more, intellisense will be a great help here. This also means that you have to actually think about what it is that this “thing” is representing, which in turn improves your design as well.

Keep it small

Keep your classes and methods small, something small is more easily to understand than something big. A good principle to help you achieve this is the Single Responsibility Principle which dictates that a class or method should only have one responsibility. When something has multiple responsibilities then you should split it up in multiple methods or classes. When correctly applied (with a little help of the Dependency Inversion Principle) this will also help you de-couple your code from each other.

Formatting

Try to format your code as good as possible, don’t put to much on a single line, make your indentation correct, don’t suddenly add many empty lines in your code. Formatting will do a lot to display the flow of your code, use it correctly.

Weird logic

When you have some weird logic like some if else statements and for loops which don’t tell you it’s intend very well, try if you can split these things up into multiple private methods purely to explain in the code why you are doing something. Use the method names to make sense of the weird logic.

In the end this is what separates you from the other mediocre developers, this is something that is more important then knowing the latest new technologies (al do some of these latest new technologies may actually help you make the code more readable and understandable). Good developers write code that functions and behaves correctly, great developers make sure that their code is also easy to be understood by other developers.

Tip: Read clean code from Robert C. Martin
Uncle bob has dedicated a whole book full with tips and tricks (ok tips and tricks sounds demeaning, but really it is a great book that every developer should read).
Sébastien Arbogast (gravatar)

In my humble opinion, you are so wrong! But you're right on one point: you put the finger right where I couldn't find the difference between them and I. When you become so self-aware and egocentric that you start to believe that your job is just to produce code (however good or bad it can be), that's when you're not part of the ecosystem anymore. That's the kind of behaviour that yields to business-IT impedance mismatch. That's the kind of belief that justifies the fact that 80% of IT projects fail. Sure, code quality and maintainability are important, but just as a means to an end, and the end is to make sure that the software we produce solves real life problems, and does so in the most reliable, flexible and durable way.

But the worst thing is that people will think you're right, including business stakeholders on the other side of the fence, the ones who think they have their business covered and that the IT guys are just here to execute their instructions and talk to the machine, without any creativity. The kind of business stakeholder I'm fed up with.

Sébastien Arbogast, Sunday, July 05, 2009 at 8:54 PM

Mark Nijhof (gravatar)

Hi Sébastien,

There always needs to be a business need to produce code, the reason is never just to produce code (except maybe in OSS). But when you are producing code it s your job to make sure it is of the highest quality you can create within the time allowed. I believe creating code that is readable and understandable doesn't take extra time, just practice.

I don't think I ever said that we are here merely to punch in the code exactly like the business people tell us to. Of course we will need to think about what is perhaps the best solution for each problem, but I also fail to see how they are in conflict with what I do say here?

Btw disagreement and discussion is the only real way to keep learning, so thank you for your comment!

Mark Nijhof, Sunday, July 05, 2009 at 10:24 PM

Thomas Hansen (gravatar)

A lot of people will tell you you' wrong and that thinking as you do is "pedantic" and such, but your main idea that the code is your product is SO right. Don't let anyone convince you aou anything else...! :)

Thomas Hansen, Monday, July 06, 2009 at 7:37 AM

Mark is reading

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.