how to comment your code?

  10 Mar 2015


Have you ever seen the following:

// To restart
void restart();

If yes, you should fight against it. This type of comment does not add any value, it is redundancy information. By writing them, the amount of code to read is increased. Have this all over in your code, and it will be like reading a book in the darkness. You will need to make an effort to sort out what information is useful, and which one is not. If the software department you work in uses tools such as doxygen with metrics about documentation coverage, then there is a good chance that you have these types of comments all over.

Now, let's look to a different kind of comment:

timer = 1000; // unit 1ms = 1sec

At first, you could assume that this is right, but what about a better naming and no comment:

timerInMilliseconds = 1000;

Regarding comments, after using different programming languages in different contexts for some years, I do largely prefer to read code which is self-explaining.

Read the comments to understand the code is like opening a dictionary to understand a discussion.

Of course there are some exceptions, like implementation of complex algorithms. But in most cases, you can achieve no comments by putting pressure on:

  • naming
  • refactoring
  • examples
  • tests

Stress this through code reviews, and you will gain one of the criteria to have a more maintainable solution.

Two additional great sources about style and commenting:

Linux Kernel Coding Style

Chapter 5: Commenting

Comments are good, but there is also a danger of over-commenting. NEVER try to explain HOW your code works in a comment: it's much better to write the code so that the working is obvious, and it's a waste of time to explain badly written code.

Generally, you want your comments to tell WHAT your code does, not HOW. Also, try to avoid putting comments inside a function body: if the function is so complex that you need to separately comment parts of it, you should probably go back to chapter 4 for a while. You can make small comments to note or warn about something particularly clever (or ugly), but try to avoid excess. Instead, put the comments at the head of the function, telling people what it does, and possibly WHY it does it.

Google C++ Style Guide

Though a pain to write, comments are absolutely vital to keeping our code readable. The following rules describe what you should comment and where. But remember: while comments are very important, the best code is self-documenting. Giving sensible names to types and variables is much better than using obscure names that you must then explain through comments.

When writing your comments, write for your audience: the next contributor who will need to understand your code. Be generous — the next one may be you!

why you should use the lean canvas if you start a new product?

  01 Mar 2015


Lean is about continuously improving your processes, avoiding wastes in anything you do, and being centered on your clients needs. As there is a tendency in any company to waste time in plenty of useless tasks, having this attitude can help.

Simply stated:

productivity = work + waste

Eliminate the wastes as much as possible and you will increase your productivity.

The lean canvas is a lean rework of the business model canvas, and was issued recently in 2009. The purpose of these two canvas is to validate or document a business model.

lean canvas

Three years ago, the offices of the company I was working for were surrounded by startups. This dynamic and creative environment had been contaminating me, and I thought, let's try it. I had identified some problems in the retail area for which I was sure to have good solutions, and I began to work on a prototype. Even if this was more a hobby project rather than a serious attempt to create a company, I had invested a crazy amount of time into it. To validate the need I had identified, I entered around 50 retails shops of the town I was leaving in, and spoke with the managers. They had even more problems than the ones I had identified, which I saw as a good sign. But after a bit more than one year, I've stopped the whole project, and one the many reasons is that I was lacking a frame helping me to focus on a solution for the market I was targeting.

One of the believes I had at this moment of time, was that you could make a good technical product, and try to push this product on the market by traction, without any business plan. Make a prototype, show the prototype, iterate, that did not work. And why? Because I did not want to invest energy into writing a business plan as this was a side project. I had few time available and tought that writing one would be a complete loss of time. This was a huge mistake, because it definitely helps to setup a frame around your project. A business plan is not just for investors, but also to help you to advance in a structured way, avoiding wastes. I wrote one, but too late, when no more energy to involve in this project was left.

As I was lacking a structure, here are some of the mistakes I did:

  • Meeting the retail shop owners was a nice experience, but they had so many problems with the existing solutions that I ended up designing a monster prototype containing too much features to implement. I had managed to form a team of 4 working on the prototype, but for the size of the team we were, that was too much and I was the one which was responsible to say "stop, let's focus". But I was throwing any decent idea that was coming into the prototype thinking that it would be easier to gain clients, and the prototype was a half-assed product in the end.
  • In this area, the acquisition client cycle is quite long (at least one year) which was an issue without investors involved in the project.
  • Going in different directions trying to please everyone in the team had been impacting the motivation of the team. You try to please everyone, and you end up pleasing no one.

Where the lean canvas can help? Because it is like a simplified and concise one view page of the business plan. You can have a first version done in 30 minutes, and have a frame to begin to move on.

  • it is easy to write
  • it is easy to understand
  • it is easy to communicate with your team if you have one
  • it is easy to update

If you try to launch a product as a side project, this is a great asset.

And everytime you look at it, it reminds you immediately something easy to forget in the life of a project: What are the problems I am trying to solve?. Here you are limited to 3 and this good. I wanted to solve 3 problems at the beginning, and 50 in the end.

I have the impression that the lean canvas is pretty popular in the startup world, but somehow, I would like to see it being used in established companies. It would probably raise the quality of internal processes, documents and deliverables being produced. It is damn simple, and complex behavior emerges from simple rules.