Using SVN to assist in commenting your code

July 18, 2007 · 9 Comment s

I'm quite heavy handed when it comes to commenting my code.

As well as inline comments, I always have a config comment at the top of every file.

In addition to basic information such as Author, Filename, when the file was created, I use Subversion to get information such as: the current revision, when was the file last updated, who updated the last file.

To automate the process, I have a CFEclipse snippet that is saved as a template (require separate ones for both CFM and CFC files). So when I create a new file, I create it from the template, and this runs the snippet automatically, prompting me to fill in certain information. You can see the snippet below.

<span class='comment'></span>

Once I commit this file to Subversion, the Subversion properties are populated, meaning I end up with something like below.

<!---
Filename: weatherProxy.cfc
Creation Date: 18/July/2007
Original Author: Andy Allan
Revision: $Rev: 45 $
$LastChangedBy: allana $
$LastChangedDate: 2007-07-18 12:24:59 +0100 (Wed, 18 Jul 2007) $
Description:
This is our proxy CFC, which in turn calls the Yahoo weather CFC as part of Ray Camden's Yahoo API package.

The component works by first being init'd, recieving a list of towns to which we have to retireve weather. At the moment this is passed in, but in time we will retrieve this information from a database as it will match all the locations for the company.

On init, we call getWeather() passing it the list of towns, and this method loops through the towns returning the weather data for each and storing in an Application
variable structure.

We then use getMyWeather() which accepts a town as an argument to return the weather data specfic to that town.

Methods:

init: This is our constructor method, which MUST be called before any other method. It takes a single
argument <span class='cc_value'>"datasource"</span> and returns itself.

getWeather: private function that loops through all the companies locations, getting their weather data and storing the data in an Application structure.

getMyWeather: method which returns the weather for a specific town.

--->

To get Subversion to actually populate your comments you need to assign a new property to every file/folder in your application.

You can either do this by running the following command:

propset -R svn:keywords <span class='cc_value'>"Rev LastChangedDate LastChangedBy"</span> /pathToFiles/trunk

Or from within CFEclipse, simply right click your Project folder and choose "Team" > "Set property" and then add the new property as indicated in the image below.

New SVN Property

With every commit, you'll now see the most up to date Subversion information directly in your comments.

Tags: ColdFusion · Subversion · CFEclipse

9 response s so far ↓

  • 1 Scott Stroz // Jul 18, 2007 at 2:36 PM

    Really dumb question coming up. How does SVN know the description and methods?
  • 2 Jim Priest // Jul 18, 2007 at 2:48 PM

    Great article!

    @Scott - in the script there are two variables:

    Original Author: $${author} - all these $${something} - are snippet variables and are populated during the insertion of the snippet

    Revision: $Rev$ - all the $something$ variables are the ones Subversion will replace
  • 3 Andy Allan // Jul 18, 2007 at 3:20 PM

    Well added Jim. I should have been more specific as to where each variable came from.

    I'll look at updating the post.
  • 4 Scott Stroz // Jul 18, 2007 at 3:23 PM

    Bah...I am an idiot. I didn't look at the variables close enough, now its kind of obvious.
  • 5 Jim Priest // Jul 18, 2007 at 3:49 PM

    I'd also add - that any svn:property you set - is applied to the repository. So if someone else comes along - checks out a working copy of this code - they will get the same behavior. Very cool!
  • 6 warhammer gold // Nov 20, 2008 at 3:32 PM

    <A href="http://www.vipwarhammergold.com/"; target=_blank><FONT =4><B>warhammer gold</B></FONT></A> <FONT =4></FONT><A href="http://www.vipwarhammergold.com/news/news.html"; target=_blank><FONT size=4><B>buy warhammer gold</B></FONT></A><BR><A href="http://www.bestwarhammer.com/"; target=_blank><FONT size=4><B>warhammer gold</B></FONT></A><FONT size=4></FONT> <A href="http://www.bestwarhammer.com/news/news.html"; target=_blank><FONT size=4><B>buy warhammer gold</B></FONT></A><BR><A href="http://www.aocsale.com/"; target=_blank><FONT size=4><B>aoc gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.aocsale.com/aoc-news/"; target=_blank><FONT size=4><B>age of conan gold</B></FONT></A><BR><A href="http://www.game4power.com/"; target=_blank><FONT size=4><B>wow gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.game4power.com/news/"; target=_blank><FONT size=4><B>buy wow gold</B></FONT></A><BR><A href="http://www.wowgoldone.com/"; target=_blank><FONT size=4><B>wow gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.wowgoldone.com/"; target=_blank><FONT size=4><B>buy wow gold</B></FONT></A><BR><A href="http://www.game4power.com/"; target=_blank><FONT size=4><B>world of warcraft gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.wowgoldone.com/"; target=_blank><FONT size=4><B>world of warcraft gold</B></FONT></A><BR><A href="http://www.gamelevelup.com/"; target=_blank><FONT size=4><B>wow power leveling</B></FONT></A><BR><A href="http://itemstores.com/"; target=_blank><FONT size=4><B>wow item</B></FONT></A>
  • 7 wholesale // Aug 8, 2009 at 6:16 AM

    Hi, good post. I have been woondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.
  • 8 ways to pass a drug test // Aug 28, 2009 at 10:18 AM

    Can i use this blog as reference in my college report
  • 9 ed hardy mens Jeans // Sep 17, 2009 at 9:20 AM

    Thank you!

Leave a Comment

Leave this field empty: