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

  • 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?

  • Netopsystems – FEAD Optimizer – Command Line

    FEAD Optimizer is a system that is used to compress installation files into a highly compact distributable file.  The intention is of course to save on bandwidth and make installation a lot more reliable.  The FEAD compressed file works sort of like an executable ZIP file.  But unlike a ZIP file there are no third party…

  • 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?

  • Windows Update or Microsoft Update

    Those of you who regularly use the Windows Update feature of Windows XP may have noticed that Microsoft have now created an enhanced version of the automated update tool. Microsoft Update has the ability to update any Microsoft application and not just Windows.

  • cURL error 28: Connection timed out

    One of my work WordPress sites is hosted internally and requires an upstream proxy to access the internet. I’ve had issues with the CRON jobs failing and the cURL error 28 message appearing, but never managed to figure out the issue until now. WordPress 5.1 brought in a new feature in the Tools menu called…

  • 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. …