Documenting scripts and source code

When writing applications, it is vital to be able to look back at your code and understand exactly what each line of code does as quickly as possible. Retrospectively Documenting scripts and source code is time consuming and prone to error, so its best to write the comments either as you are writing the code,…

When writing applications, it is vital to be able to look back at your code and understand exactly what each line of code does as quickly as possible. Retrospectively Documenting scripts and source code is time consuming and prone to error, so its best to write the comments either as you are writing the code, or as soon as a particular block of code is complete. Here’s how to do it…

When writing applications or scripting useful functions, it is always helpful to document the code as you go along so that, should you ever need to tweak the code, you’ll know exactly what each line of code does at a glance.  The keyword or character that you use to mark the line as a special comment line will vary depending on the language that you are using.

Fortunately Microsoft have very kindly standardised on the line starting with REM for Visual Basic which then renders everything after that keyword as a comment for instance:

REM This loop acts a counter
REM set the initial count value to 0
i=0
REM set up a loop that executes until the counter value reaches 10
do while i <= 10
REM write to screen the current value of the counter
Response.Write "i currently equals: " & i & "<br>"

REM add one to the value of the counter
i = i + 1

REM Restart the loop until the counter is equal to 10
loop
REM End the loop

As you can see, by using REM I can tell myself or another technician modifying this script exactly what each line of code does and why. Useful! I document the whole of my Cisco network in this way!

Other languages

Batch (BAT/CMD)REM or :: (double colon)
Visual BasicREM or ‘ (apostrophe)
AutoIT; (semi colon)
PHP// (double forward slash)
Delphi{} (encased in curly brackets)
c#// (double forward slash)

Similar Posts

  • FEAD Optimizer Extract Tool

    It has finally arrived.  Introducing the FEAD Optimizer Extraction tool. This tool is designed to allow the quick extraction of a FEAD Optimized installer application such as Acrobat Reader.  I am surprised that NetOpSystems who make FEAD have not developed an application for network administrators that will allow easy extraction of the proprietary compressed files. …

  • The Ultimate Boot CD

    For the past year or so, I have been using a magical bootable CD that enabled me to boot a computer into a working version of Windows XP so that I could recover files, run diagnostics or Ghost a hard drive to another machine.  What is this magical CD?

  • Need to copy files across a network? Use RoboCopy

    If you are migrating a file server or just have lots of files to copy from one networked machine to another, then instead of using the Windows Explorer method of copying the files, why not use RoboCopy?

  • Internet Explorer Max Connections

    If you are using a broadband connection it can be quite frustrating having to wait for Internet Explorer to finish rendering a web page.  Internet Explorer has a built in limit to the number of items that can be downloaded at any one time.  This limitation has been defined as part of the HTTP Specifications. …

  • Internet Explorer Proxy settings

    Here is a bit of VB Script that will change the proxy settings of a machine if you are unable to access the Internet Explorer control panel or the Windows Registry. USE AT YOUR OWN RISK