Guidelines for naming variables, subroutines, and scripts

You need to make sure you give meaningful names to variables, subroutines, and scripts. When you use meaningful names, you avoid assumptions and confusion.

Use names that express the purpose of a variable, subroutine, or script

A variable, subroutine or script name should state its purpose. The name should answer:

  • Why you need that variable, subroutine, or script?
  • What is this variable, subroutine, or script doing or storing?

Bad example:

Default for bad names

Good example:

Default for good names

Use pronounceable names

Pronounceable names facilitate communication and collaboration.

Bad example: cpCltDir

Good example: copyClientDir

Define naming conventions and standards at the beginning of a project

If you define naming conventions and standards before the team starts working on the project, you ensure that the team develops consistently.

Good example:

Variable names
"Camel Case" standard starting with a lowercase letter as in excelRow.

Constant names
"ALL_CAPS" standard separating with an underscore as in MAX_ROWS.

Subroutine names
"Camel Case" standard starting with a capital letter as in GetFile.

Language used
If possible, use English in projects unless the Project Owner requests a different language.

Name subroutines or scripts according to the action you programmed them to do

Use names that clearly express the subroutine or the script's purpose. The name should state what the subroutine or script does in that context.

Bad example: A bad example is to name a subroutine InsertItem when this subroutine does more than inserting an item into a system. For example, this subroutine gets the item data before inserting the item. Either split this subroutine into more subroutines or name it something else.

Good example: Considering the bad example, you could split InsertItem into GetItemData and InsertItem.

Variable name conventions

You can use the following variable naming conventions when developing scripts.

Name variables according to their meaning

Bad example: ${success} stores the login operation status.

Good example: ${loginSuccessful} stores the login operation status.

Bad example: ${count} stores the number of successfully processed files.

Good example: ${filesProcessedWithSuccess} stores the number of successfully processed files.

Use one word per concept and keep it consistent

If you named a variable that stores the average height as avg_height, then you should use avg_ anytime a variable stores some average value to maintain consistency. The rationale is to keep names consistent throughout your script.

Bad example: avg_height and averageWidth.

Good example: avg_height and avg_width.

Subroutine naming conventions

You can use the following subroutine naming conventions when developing scripts.

Name subroutines with at least one verb and one noun

The verb must be in the present indicative mood.

Bad examples:

  • Email
  • Save

Good examples:

  • SendEmail
  • SaveFile

Script naming conventions

You can use the following script naming conventions when developing scripts.

Name a script to indicate the context to which it belongs

Scripts that belong to the same context must start by naming the context, following the same subroutine rule: verb + noun. The verb must be in the present indicative mood.

Good examples:

  • fooSystem_loginSite
  • fooSystem_downloadArchives
  • varSystem_extractDataInvoices
  • barSystem_setDataInvoices
  • sendEmail

When naming scripts for generic purposes, you can omit the context like in sendEmail.