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

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

  • 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

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

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

  • Take control of Domain Passwords with Password Control

    There are many ways to change passwords on a Windows Active Directory Domain.  Users can change their own passwords on the workstation.  However for Network administrators there are not any built-in tools for administrating other user network passwords, unless you Remote Desktop to the Domain Controller or have installed the local support tools for Active…