Comments

At work I (with heavy input from the rest of the team) am writing these guidelines for our development practices, so that everyone is working 'on the same page.' I will share this series here for others who may want to know how some folks do it.

First and foremost is documentation. We have an extremely large system, currently made up of nearly 7,000 ColdFusion, XML, Javascript, Cascading Style Sheet, ActionScript, and Flash templates. The original authors of these templates were spread fairly thin, working a variety of tasks while attempting to produce a usable product base to build our company upon. Because of this a large majority of our system is completely un-documented. Now, as a matter of standard practice, every template touched by a developer is given, at minimum, a document header comment to create some form of initial documentation.

<cfsetting enablecfoutputonly="true">

<!---
===========================================================================
// CLASS/COMPONENT:
// wwwroot.Admin.myComponent
//
// DESCRIPTION:
// Here is a brief description of 'myComponent'
//
// AUTHOR:
// Steve 'Cutter' Blades (SGB), web.adminATcutterscrossingDOTcom //
// COPYRIGHT:
// Copyright (c) 2007 CuttersCrossing, Inc. All Rights Reserved.
//
// REVISION HISTORY:
//
// *****************************************************************************
// User: SGB Date: 01.14.07
// Initial Creation
// ******************************************************************************
===========================================================================
--->


<!--- The rest of the code is included here --->

<cfsetting enablecfoutputonly="false">

This is a very basic header comment. Opening and closing comment identifiers will be different for Javascript, ActionScript, Flash files, or Style Sheet documents, but the basic structure would be the same. First you have the path to the document being worked on. This is a dot notated reference to the path, in this case a ColdFusion Component (myComponent.cfc) locatated in /wwwroot/Admin/. Documents other than component classes would also include their document extension (i.e.: wwwroot.Admin.myTemplate.cfm). A brief description of what the template does is included next, followed by the name and email of the author of the template (only to be used on new documents), and the copyright notice. The final area is the revision history. This is the most important area within this documentation, as every change made to a template will be documented here, with the most current revision being the top item then going downward for each revision made to a template. Each revision will be listed with as much detail as possible, stating the initials of the developer making a change and the date that it was modified. Similar revision notes should also be made inline within the document at the location of any revisions, with the same data included (initials and date stamp). You should also note the cfsetting tags. These are utilized to minimize white space output in the generated page, and are only used within .cfm templates, but require the developer to pay close attention to the code contained between them, as display code will only be rendered if it exists within cfoutputtags (or within the writeoutput() statement of a cfscript block.

Inline revisions:

<!---
//   SGB [11/27/2006]:   Added a param in the event that the value is not included within the querystring
--->

<cfparam name="url.event" default="" />

JavaScript example:

/*
//   Function to validate a form
// Input: fields array of fields to be validated
// Output: boolean value for success or failure
*/

function validateForm(fldsObj){
   success = 1;
   // Validation processing would reset 'success' on failure
   return success;
}

Comments are handled differently with different languages:

  • ColdFusion (CFML) - <!--- Comment --->
  • HTML/XHTML - <!-- Comment -->
  • Cascading Style Sheet - /* Comment */
  • ColdFusion (CFScript), JavaScript, Flash/ActionScript -
    • Multiline - /* Comment */
    • Single Line - // Comment

Related Blog Entries

Comments
Sam's Gravatar Out of curiousity, how many files/components are you finding named, for instance, Math.cfc, have descriptions like "This file contains several math functions." ?

Also, what happens when the person whose contact information is in the file no longer works with you, or is that not a concern?

Were you finding that the original programmers were using hard-to-discern meaning in their choice of variable and file names?
# Posted By Sam | 1/15/07 8:37 AM
sporter's Gravatar You seemed to describe the behavior of enablecfoutputonly="true" but your code sample has enablecfoutputonly="false". Which do you guys use? I use enablecfoutputonly="true" in every CF app I do... for white space control, like you describe.
# Posted By sporter | 1/15/07 9:53 AM
Dan G. Switzer, II's Gravatar I use to be horrible at documenting code, but over the years it's a development practice I've learned to be thorough at. I even use a different syntax for permanent comments and temprorary comments. For example, I use &lt;---// comment //---&gt; for all permanent descriptive comments and just &lt;--- ---&gt; for any temporary comments used to comment out blocks of code. I find this makes it very easy when reading scripts to determine the difference in the comment. I know if it doesn't have the double slashes, the comment was not made to be permanent. This makes it easy to remove dead code that may have been left in for easy rollback.
# Posted By Dan G. Switzer, II | 1/15/07 11:28 AM
Cutter's Gravatar Sam:
Our system at work is a shared template application setup, consisting of something near to 7,000 CF templates, CF components, JavaScript files, Flash files, and XML documents, developed over the last 5-6 years by just under a dozen different programmers. Prior to my immediate boss being hired there was almost never any documentation within the code, variable scoping is abismal, etc. Anything my boss generated was built with some more forthought, and once I was hired every template touched received documentation (at the least). Now that we have hired two new developers (one senior, one entry) we realized we really needed to standardize.....And yes, we had variables of totally unknown scope named 'i', and files like 'FormProcessor.cfm'. "let's guess where this one belongs..."

sporter:
Yes, it is for white space suppression. If you take a closer look at the example you will see a 'Your code goes here' comment prior to the enablecfoutputonly="false" line. The reason we open and close it (or close it and open it, depending on your point of view) is because you never know when the file you are working on may be a cfincluded template. The including template might not have processing directives (yet) and we don't want to 'hide' any content inadvertantly.

Dan:
Fantastic idea for delineating 'temp' and 'perm' comments. Might have to adopt that.
# Posted By Cutter | 1/17/07 11:00 PM
Sam's Gravatar Cutter - I see! I've been in a similar situation, and I did have trouble sometimes. How long have these rules been in place, and are you finding that they are alleviating problems, or is it still too soon to tell?
# Posted By Sam | 1/18/07 7:40 AM
Tom's Gravatar Well, 7,000 templates is a small system. I am dealing with around 700,000 CF, Flash, XML etc. templates. Standards are nice, but for some reason they are hard to enforce on different developers. The reality is, if you don't refactor your code you are going to end up with a mess at some point no
matter what you do.
# Posted By Tom | 2/1/07 1:27 AM
BlogCFC v. 5.8.001 was created by Raymond Camden. Layout inspired by bluerobot.com., with some JQuery thrown in for fun.