Naming convention (data processing)

from Wikipedia, the free encyclopedia

Naming conventions are specifications / requirements / recommendations for programmers , database developers , etc. to name identifiers (names) for objects in the source code of software . When they are used, the names of these objects - within the framework of the syntax provisions of the programming language and also across programs - should be formed according to uniform rules, whereby the software quality feature changeability (maintainability) is supported by easier understanding of the program text.

Such rules apply - mostly company- or project-specific - constructs generally used for all programming - such as data fields ( variables , constants ), objects , functions , types , classes , modules , procedures , command text sections, etc. and are intended to be "readable code" contribute .

Similar conventions (they are almost always denoted with the plural) exist for the indentation style and for inserting comments in the source code of programs.

Naming conventions are structurally / methodologically part of the programming guidelines and a. the programming style for the program code. Depending on the situation / company, they can be binding or formulated for voluntary use.

Examples

Hungarian notation

In the Microsoft world, the so-called Hungarian notation was used in the past , in which the beginning of an identifier can be used to infer its type or purpose. In the meantime, however, Microsoft prohibits the use of Hungarian notation. Instead, variables should be named according to clean code guidelines.

Coding of the type in the name

From programming for whole numbers, floating point numbers , special formats and strings:

  • bytZaehler for a counter variable of the byte type (up to size 255),
  • intZaehler for a counter variable of the type integer (from −32768 to +32767),
  • lngZaehler for a counter variable of type long (> 32767),
  • sngQuotient for the floating point result of a division of the type Single,
  • dblQuotient for the floating point result of a division of the type Double,
  • curNetto for currency amounts of the type Currency,
  • strVorname for alphanumeric strings of the string type,

Coding of the use in the name

For objects (here: relational database ):

  • tblKunde for a table containing customer master data,
  • qryPLZ4 for a query that collects all customers from the postcode area 40000 to 49999,
  • frmAuftrag for a form in which customer orders can be entered / displayed / changed / deleted,
  • repUms2005-12_Knd1010 for a report in which all sales of the customer with customer number 1010 are listed, which were made in December 2005.

Constants in C

In the C programming language and other parts of the Unix world, it is common to declare constants in capital letters (e.g. sngUMSATZSTEUER_ERMAESSIGTfor the reduced sales tax rate) - especially for preprocessor macro parameters.

Naming conventions for Java

The programming guidelines for the Java programming language define naming conventions for various linguistic elements, regardless of their use. Basically Java identifiers are with medial capitals are written (even camel hump notation , Eng. CamelCase called) and no underscores ( "_") included, with the exception of constants (see below).

  • Class names should be nouns and begin with a capital letter, e.g. B. Stringor ArrayList.
  • Method names should be verbs and begin with a lowercase letter, e.g. B. addor remove. Query methods in particular often deviate from this rule in that they are not verbs and are instead called, for example, toStringor isEmpty.
  • Constant names should only be written in capital letters, with the individual words separated by underscores, e.g. B. MIN_VALUE.

Reddick naming conventions

Instructions for naming variables, as a variant of this as "Leszynski naming convention" (LNC) i. W. applied for use under Microsoft Access and Visual Basic for Applications .

More naming rules

Further specifications or recommendations for naming objects in the source text, often only intended as recommendations, can be:

Speaking object identifier

For constructs that are addressed in the programming via identifiers , naming conventions can be used to specify that these are largely selected as "speaking". This means that the identifiers (in the context of the program environment) should be more or less "self-explanatory" in order to show the semantic meaning and use of the elements to people who were not involved in the initial development of the program .

In addition to and more precisely to purely colloquial identifiers (such as "invoice amount"), it can be specified, for example, whether the identifier can / should consist of several parts (e.g. to differentiate between objects in different roles), whether format information should be included in the object description the order in which name parts are to be arranged, whether individual components of the identifier z. B. with a hyphen or an underscore or separated whether abbreviations are to be used.

Example with counterexample: MWSt_Betrag = Rechn_Betrag_Nto * MWSt_Prozentinstead ofBetrag1 = Betrag2 * Prozent

In the early days of data processing - e.g. B. by programming languages ​​or the use of punch cards - existing restrictions in the length of identifiers are usually no longer relevant in today's systems.

Other naming concepts

In programming, it is common to use descriptive names to identify several other (relatively independent) properties of the elements in addition to the functional meaning in the application (the semantic meaning), for which some common concepts of prefixes / suffixes in the identifier have emerged:

See also

Individual evidence

  1. Databases understand naming conventions
  2. Uni Tübingen Software Engineering Best Practices Writing readable code
  3. ^ Naming Guidelines. In: MSDN. Microsoft, accessed July 30, 2014 .
  4. ^ Naming Conventions. Oracle, accessed July 30, 2014 (English, naming conventions for the Java programming language).