Ada 95 Quality and Style Guide Chapter 5

Chapter 5: Programming Practices - TOC - 5.5 EXPRESSIONS

5.5.4 Positive Forms of Logic

guideline

  • Avoid names and constructs that rely on the use of negatives.
  • Choose names of flags so they represent states that can be used in positive form.

  • example

    Use:

    if Operator_Missing then
    

    rather than either:

    if not Operator_Found then
    

    or:

    if not Operator_Missing then
    

    rationale

    Relational expressions can be more readable and understandable when stated in a positive form. As an aid in choosing the name, consider that the most frequently used branch in a conditional construct should be encountered first.

    exceptions

    There are cases in which the negative form is unavoidable. If the relational expression better reflects what is going on in the code, then inverting the test to adhere to this guideline is not recommended.


    < Previous Page Search Contents Index Next Page >
    1 2 3 4 5 6 7 8 9 10 11
    TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC
    Appendix References Bibliography