|Ada 95 Quality and Style Guide||Chapter 3|
3.2.3 Object Names
Use predicate clauses or adjectives for Boolean objects.
Use singular, specific nouns as object identifiers.
Choose identifiers that describe the object's value during execution.
Use singular, general nouns as identifiers for record components.
Non-Boolean objects:Today : Day; Yesterday : Day; Retirement_Date : Date;
Boolean objects:User_Is_Available : Boolean; -- predicate clause List_Is_Empty : Boolean; -- predicate clause Empty : Boolean; -- adjective Bright : Boolean; -- adjective
Using specific nouns for objects establishes a context for understanding the object's value, which is one of the general values described by the subtype's name (see Guideline 3.2.2). Object declarations become very English-like with this style. For example, the first declaration above is read as "Today is a Day."
General nouns, rather than specific, are used for record components because a record object's name will supply the context for understanding the component. Thus, the following component is understood as "the year of retirement":Retirement_Date.Year
Following conventions that relate object types and parts of speech makes code read more like text. For example, because of the names chosen, the following code segment needs no comments:if List_Is_Empty then Number_Of_Elements := 0; else Number_Of_Elements := Length_Of_List; end if;
If it is difficult to find a specific noun that describes an object's value during the entire execution of a program, the object is probably serving multiple purposes. Multiple objects should be used in such a case.
|< Previous Page||Search||Contents||Index||Next Page >|