Page 217 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 217
Unit 10: Coding Standards
Avoid the use of forced data conversion, sometimes referred to as variable Notes
coercion or casting, which may yield unanticipated results.
10.3.2 Coding Techniques
Coding techniques incorporate many facets of software development and, although they
usually have no impact on the functionality of the application, they contribute to an improved
comprehension of source code. For the purpose of this document, all forms of source code are
considered, including programming, scripting, mark-up, and query languages.
The coding techniques defined here are not proposed to form an inflexible set of coding
standards. Rather, they are meant to serve as a guide for developing a coding standard for a
specific software project.
The coding techniques are divided into three sections:
• Names
• Comments
• Format
Names
Perhaps one of the most influential aids to understanding the logical flow of an application is
how the various elements of the application are named. A name should tell “what” rather than
“how.” By avoiding names that expose the underlying implementation, which can change,
you preserve a layer of abstraction that simplifies the complexity. For example, you could use
GetNextStudent() instead of GetNextArrayElement().
A tenet of naming is that difficulty in selecting a proper name may indicate that you need to
further analyze or define the purpose of an item. Make names long enough to be meaningful but
short enough to avoid being wordy. Programmatically, a unique name serves only to differentiate
one item from another. Expressive names function as an aid to the human reader; therefore, it
makes sense to provide a name that the human reader can comprehend. However, be certain
that the names chosen are in compliance with the applicable language’s rules and standards.
Following are recommended naming techniques:
Routines
• Avoid elusive names that are open to subjective interpretation, such as Analyze() for a
routine, or xxK8 for a variable. Such names contribute to ambiguity more than abstraction.
• In object-oriented languages, it is redundant to include class names in the name of class
properties.
• Use the verb-noun method for naming routines that perform some operation on a given
object, such as CalculateInvoiceTotal().
• In languages that permit function overloading, all overloads should perform a similar
function. For those languages that do not permit function overloading, establish a naming
standard that relates similar functions.
Variables
• Append computation qualifiers (Avg, Sum, Min, Max, Index) to the end of a variable
name where appropriate.
• Use customary opposite pairs in variable names, such as min/max, begin/end, and open/
close.
LOVELY PROFESSIONAL UNIVERSITY 211