Page 218 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 218

Principles of Software Engineering



                   Notes            •  Since most names are constructed by concatenating several words together, use mixed-case
                                      formatting to simplify reading them. In addition, to help distinguish between variables and
                                      routines, use Pascal casing (CalculateInvoiceTotal) for routine names where the first letter
                                      of each word is capitalized. For variable names, use camel casing (documentFormatType)
                                      where the first letter of each word except the first is capitalized.
                                    •  Boolean variable names should contain Is which implies Yes/No or True/False values,
                                      such as fileIsFound.
                                    •  Avoid using terms such as Flag when naming status variables, which differ from Boolean
                                      variables in that they may have more than two possible values. Instead of documentFlag,
                                      use a more descriptive name such as documentFormatType.
                                    •  Even for a short-lived variable that may appear in only a few lines of code, still use a
                                      meaningful name. Use single-letter variable names, such as i, or j, for short-loop indexes
                                      only.
                                    •  If using Charles Simonyi’s Hungarian Naming Convention, or some derivative thereof,
                                      develop a list of standard prefixes for the project to help developers consistently name
                                      variables. For more information, see “Hungarian Notation.”

                                    •  For variable names, it is sometimes useful to include notation that indicates the scope of
                                      the variable, such as prefixing a g_ for global variables and m_ for module-level variables
                                      in Microsoft Visual Basic.
                                    •  Constants  should  be  all  uppercase  with  underscores  between  words,  such  as  NUM_
                                      DAYS_IN_WEEK. Also, begin groups of enumerated types with a common prefix, such
                                      as FONT_ARIAL and FONT_ROMAN.
                                 Tables
                                    •  When naming tables, express the name in the singular form. For example, use Employee
                                      instead of Employees.
                                    •  When naming columns of tables, do not repeat the table name; for example, avoid having
                                      a field called EmployeeLastName in a table called Employee.
                                    •  Do not incorporate the data type in the name of a column. This will reduce the amount
                                      of work needed should it become necessary to change the data type later.
                                 Microsoft SQL Server
                                    •  Do not prefix stored procedures with sp_, because this prefix is reserved for identifying
                                      system-stored procedures.
                                    •  In Transact-SQL, do not prefix  variables with @@, which should be reserved for truly
                                      global variables such as @@IDENTITY.
                                 Miscellaneous
                                    •  Minimize the use of abbreviations. If abbreviations are used, be consistent in their use.
                                      An abbreviation should have only one meaning and likewise, each abbreviated  word
                                      should have only one abbreviation. For example, if using min to abbreviate minimum,
                                      do so everywhere and do not later use it to abbreviate minute.
                                    •  When  naming  functions,  include  a  description  of  the  value  being  returned,  such  as
                                      GetCurrentWindowName().
                                    •  File and folder names, like procedure names, should accurately describe what purpose
                                      they serve.



        212                               LOVELY PROFESSIONAL UNIVERSITY
   213   214   215   216   217   218   219   220   221   222   223