0

Is there a standard template to use for .NET source code files?

I am accustom to putting my header information between /* */ tags, but StyleCop is complaining about those.

2
  • What are you putting inside a comment? some sort of boilerplate for the file with author, revision history and the like? Jun 3, 2009 at 14:32
  • Yes, I would have the author, file name, copyright, revision history, etc in the header.
    – Dan
    Jun 3, 2009 at 14:53

2 Answers 2

2

Never put revision history in the source file, that's what your source control system is for.

as for headers I would suggest that #region is a good idea (since it is boiler plate that should be removed from your concern unless you are editing it at which point it doesn't matter if it is // or /*.

Since // is more robust (no nesting issues) // is preferred

1
  • I liked the comment, revision history in the source file. I think it's debatable a bit.
    – sarat
    Jun 15, 2011 at 6:57
1

Just a thought and by no means a standard (or for that matter, possibly a good idea). Have you thought about maybe using attributes? E.g.

[Author("Jonathan Dickinson")]
[Copyright("Copyright (c) Jonathan Dickinson 2009")]
[RevisionHistory(
        "jcd: Made the class.",
        "jcd: Made the class internal.")]
[License("GPL", LicenseType = LicenseType.CopyLeft)]
// Etc.
class Foo
{
}

Anyone have any ideas why this would be a terrible practice?

In any case - StyleCop was made primarily for commercial projects (who typically don't do code headers). In other words - ignore or disable the friggen warning. Time and time I have read that StyleCop and FXCop are too nit-picky. I have seen header comments in the following format.

// <code-header>
//  <author>Jonathan Dickinson</author>
//  <copyright>Copyright (c) Jonathan Dickinson 2009</copyright>
//  <license href="license.txt">New BSD</license>
//  <revisions>
//    <revision initials="jcd">Made the file and class</revision>
//    <revision intiails="jcd">Made the class internal</revision>
//  </revisions>
// </code-header>

It has obvious advantages - statistics (like Ohloh does) and verification of a code-base come to mind straight away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.