What should I put in header comments at the top of source files?

Date created, date modified and author who last changed the file should be stored in your source control software.

I usually put:

  • The main purpose of the file and things within the file.
  • The project/module the file belongs to.
  • The license associated with the file (and a LICENSE file in the project root).
  • Who is responsible for the file (either the team, person, or both)

This seems to be a dying practice.

Some people here on StackOverflow are against code comments altogether (reasoning that code should be written to be self explanatory) While I wouldn't go that far, some of the points of the anti-comment crowd make sense, such as the fact that comments tend to be out of date.

Header blocks of comments suffer from these symptoms even more so. Every organization I've been with that has had these header blocks, they are out of date. They have a author name of some guy who doesnt even work there any more, a description that does not match the code at all (assuming it ever did) and a last modified date, that once compared with version control history, seems to have missed its last dozen updates.

In my personal opinion, keep comments close to the code. If you want to know purpose of, and/or history of, a code file, use your version control system.


What fields do you need? If you have to ask whether to put some info there, you don't really need that info. Unless you are forced, by some bureaucratic incompetence of your employer, I don't see why you should go looking for more info than you already feel should be there.\


Back in 2002, when I was straight out of college and jobs were few and far between after the dot-com bust, I joined a service company which used to create software customized for their clients in Java. I had to sit in the office of a client (which was a ramshackle room in an electric sub-station rigged with an AC to keep the servers running), sharing chairs/PCs with other guys in the team. The other engineers (if I can call them engineers ;) in the group used to make changes ad-hoc to the source code, compile the files and put them into production.

  • No way to figure out who made what change.
  • No way to figure out why any change was made.
  • No way to go to previous version of code, unless the engineer "remembered" what he modified.
  • Backup: Copy over files from the production server, which were replaced with new files.
  • Location of backup: Home directory of engineer copying over files to production server.

Reports of production servers going down due to botched attempts of copying over files to the server (missed a file to be copied over, backups getting lost or wrong files being copied over or not all files being copied over) were met with shrugs (oh no, is it down? let's see what happened; hey who changed what recently...? ummm...).

During those days, after spending several frustrating days trying to figure out the whos and whys behind the code, I had devised a system for comments in a list in the header of the source file which detailed the following:

  1. Date of change made
  2. Who made the change
  3. Why was the change made

Two months later when the list threatened to challenge the size of the source code in the file, the manager had the bright idea of getting a source version control system.

I have never needed to put any comments in headers of source files (except for copyright notices) in any company I worked since. In my current company, everything else is mostly self-evident by looking at the code, or going to the bug reporting system which is integrated with the source version control system.