tags:

views:

353

answers:

5

What information do you consider worth to put in the comment at the beginning of a sourcecode file?

All I could think about was the name of the author and perhaps the date the file was created (although I'm not to sure if there is any useful value to this information).

[EDIT] To clarify, I don't mean comments before a class, but at the first lines of the file, before include statements and what else. Like

/**
 * Author:    Name
 * Created:   11.05.2009
 * 
 * (c) Copyright by Blub Corp.
 **/
A: 
  • Copyright
  • Original author(s)
  • License (if it's open-source)
  • One-line purpose statement or description
  • Further overall documentation and usage examples

Edit: Changed Author(s) to Original Author(s)

a paid nerd
+1  A: 

if the file is going to contain some very common class / functionality which can be understood with reasonable common sense, then you dont really need to put much in the description otherwise if the source code file is a class / function very specific to the project or is encompassing a complicated logic, then you should give a high level overview & purpose of the source code file.

Vikram
I think you misunderstood me (meaning I should have been more precise, then ;) ). I don't mean comments to put before a class or function, but at the top of the file, even before include statements etc.
Michael Barth
A: 

File Encoding! (utf-8)

# -*- encoding: utf-8 -*-

Especially if you plan on sharing your code with someone else in some other part of the world at some point.

monkut
Unless it's ASCII. Most of my source files are ASCII, except those containing user-visible strings.
pts
Uhm, if you have mixed encodings in a project, wouldn't you say it's twice as important to add encoding information to show that you didn't just forget saying this file is supposed to be UTF-8? Of course, to avoid confusion it's better to consistently use one encoding across all files of your project (and the correct encoding to use is almost invariably UTF-8).
gustafc
I put utf8, as it's generally what you want to be using as your encoding.
monkut
+12  A: 

What to put in the file header:

  • Library/component that source code is part of
  • Copyright details
  • Brief and meaningful description of class(es) in source file

What NOT to put in the file header:

  • Anything that duplicates low level logic which is part of the code itself. This can lead to maintenance problems if it isn't updated when the source code changes.

  • Author name(s). Why?

    • In the world of revision control systems, while there may be an initial author of some code, eventually ownership becomes blurred. This is especially true when code enters the maintenance phase of the life cycle where owners can change regularly.
    • All code eventually becomes "community wiki" after enough changes ;-)
    • Would you want your name associated with all of the code forever, knowing full well that you will not be responsible for the code until its death?
  • Creation and last changed dates. This is for similar reasons as list above. Revision control includes this information - why duplicate it in the header, making more work for yourself and risking leaving inaccurate information in the comment when things inevitably change?

LeopardSkinPillBoxHat
Nice points against putting the author name there. Do you think it's necessary to put a library/componet information there in C#, where every file is in a certain namespace which already includes the component information (at least in my designs)? Like: namespace Company.Component.SubComponent
Michael Barth
@Michael - I think if the file/class/namespace structure is self-documenting like you suggested, this is probably redundant information and shouldn't be included.
LeopardSkinPillBoxHat
I'd also add the compiler name (but NOT compiler version, as that could change in the lifetime of a project, and so should go in a release checklist or similar), and for embedded software, the target processor.
Steve Melnikoff
A: 

with all the above also put sort detail of the purpose of the code in that file also something u think can be helpful in debugging and understanding the functionality.this help in maintainence and support.

Vinay Pandey