When developing software programs, it is a good idea to follow a set of programming standards. Doing so allows your program to be more understandable by others as they encounter a program that is predictably organized and uses the same nomenclature. It is especially important to institute programming standards when jointly drafting programs with a team of developers, as personal programming styles can interfere with the overall comprehension of the programs.
The list below provides a good starting point towards developing a common set of programming standards. Your standards may differ, but establishing and using a common set of standards is a key component of maintaining good programming practices.
- Establish a version control system. Git is one such system, which is available for download free of charge.
- Backup your programs and all components used by your program on a regular basis (daily or several times a week is a good schedule, depending on the number of changes being made). If you are working as part of a team, other team members may need your updates, so be aware of their needs when deciding when to make a backup.
- Compile your program regularly (daily or several times a day) when changes are made, as this will help you identify and resolve syntax and logic errors more quickly.
- Utilize the CSPro help system and CSPro's reference window as needed to assist with logic development (press F1).
- Add comments to your logic (functions, PROCS, code blocks, etc.) to document your work, ideally when adding or revising your program. (Adding comments later often never happens, and you are less likely to remember why you coded something a certain way.) Remember when working in a team environment that others will be reviewing and possibly modifying your code, and they need to understand what is happening.
- Indent your code to reflect your program's execution hierarchy within conditional statements (if), loops (do, for, forcase, while), and functions. You can let CSPro format your entire program by choosing Edit > Format Logic within the CSPro development environment.
- Use UPPERCASE when writing CSPro dictionary variable names.
- Use mixedCase when writing globally and locally-declared variables (often referred to as using "camelCase").
- Declare constants in CSPro's PROC GLOBAL block rather than elsewhere in the program.
- Use locally-declared variables when only one procedure, function, or code blocks needs to reference the variable. Remember that the value of the local variable will be reset each time the code block is re-executed (to zero if numeric, to an empty string if alpha).
- Create functions to optimize repetitive code blocks (i.e., if the same task will be done in several parts of your program), or if you have a long code block, and moving the logic to a function would facilitate program legibility.
- Consider creating standardized prefixes for variable names. For example:
- cnt: when counting an item (such as cntPersons and cntHouseholds)
- ptr: pointer to a record (for instance ptrEldest is the occurrence number of the eldest resident)
- b: indicating a boolean variable (such as bAdult and bChild when needing a variable to represent a true/false condition
- Maintain an error message numbering scheme for CSEntry and CSBatch applications so that interviewers, subject-matter specialists, programmers, and anyone else using your application can understand where error messages occur. For example, suppose a 5-digit error message used the following syntax (RQQQN), where:
- R = record type designation (1 digit)
- QQQ = question number of the primary variable being reported on (3 digits)
- N = error number for this variable (1 digit), which allows up to 10 messages to be associated with this variable (0-9)
(Note that while record type designations in CSPro can also use alpha characters, error message numbers must be entirely numeric.) - Do not use deprecated features, as they may not be supported in a future version of CSPro.
- Take advantage of free support from the U.S. Census Bureau at the CSPro Users forum (preferred) or via email at cspro@lists.census.gov.