Script Development Best Practice

I’ve seen a number of posts on a variety of forums from new and beginning scripters. Typically the question is how to achieve a certain task, but it got me thinking about this from another angle: what is the best practice for starting a new script?  My answer: Comments.

When you are starting a new script project, open up your script editor (hopefully Primal Script which has a helpful feature I’ll cover a little later) and start a new script. But before you write a single line of code, step through what you need the script to do.  In your script create a comment that describes each step. The more specific and detailed the better.  This serves several purposes.  First, it forces you to develop at least a rough draft of the script logic. Once you know what each part of the script needs to accomplish you can develop the code or search for existing samples that you can modify and plug in. When the script is finished, all your comments serve as script documentation.  We always stress how important it is to document your script. If this step is put off to the end, it rarely happens. If you document what the script is doing before you begin, your script development will be easier and the documentation task is done as well!

PrimalScript 4.1 has a new feature call a TaskList browser that takes this to the next level. This feature can be displayed in either the right or left nexus windows. When you create a script, create the comment like this:

‘TODO: Prompt for Username

The Tasklist browser will parse this out of the script and list it in the nexus window. When finished with the task, change it to ‘DONE: and the tasklist browser will reflect that.

PrimalScript 4.1 TaskList Browser

When your script is finished, you can leave the comments as they are, or go through and change ‘DONE: to just the comment character ‘, which leaves behind all your documentation.

So the next time you are starting a new script, document with comments everything the script will be doing. Your script will have few bugs, it will be easier to develop and it will be documented.