3.3.2 The project shall ensure that software coding methods, standards, and/or criteria are adhered to and verified.
1.1 Notes
NPR 7150.2, NASA Software Engineering Requirements, does not include any notes for this requirement.
1.2 Applicability Across Classes
Classes F and G are labeled with "X (not OTS)." This means that this requirement does not apply to off-the-shelf software for these classes.
applicable
f
*
g
*
h
0
ansc
1
asc
1
bnsc
1
csc
1
bsc
1
esc
1
cnsc
0
dnsc
0
dsc
1
ensc
0
Div
id
tabs-2
2. Rationale
NASA programs and projects have multiyear life cycle times. Often the software personnel who develop the original software work products move on to other projects. These developers are then backfilled on the team by other developers for the remainder of development, for operations, maintenance, and disposal phases of the life cycle. This personnel turnover process may occur several times during the project's life cycle. The use of uniform software coding methods, standards, and/or criteria ensures uniform coding practices, reduces errors through safe language subsets, and improves code readability. Verification that these practices have been adhered to reduces risk of software malfunction for the project during its operations and maintenance phases.
Div
id
tabs-3
3. Guidance
Coding standards are used to prevent or reduce unsafe coding practices. Planning for the adoption and use of coding standards at the beginning of a software development activity sets the right tone and approach for the development team.
Software coding standards are classified by language, usage, and severity levels. Language specific rules and best coding practices are usually determined by experts in the particular language [e.g., C++, ADA] and tailored as needed by the project. Usage types and severity levels are set by the user.
sweref
326
326
Panel
To assist you in fulfilling this requirement, interpret the text in section 1 as "software coding methods," "software coding standards," and "software coding criteria." Also, interpret the terms "methods" and "criteria" as being indictive of the style of the software developer.
Over time, correlations between bugs and coding practices resulted in a set of rules that helped to prevent coding errors from occurring.
sweref
326
326
These activities resulted in recommendations to develop and use coding standards.
Floatbox
width
full
"A comprehensive coding standard encompasses all aspects of code construction. ...Properly completed source code reflects a harmonized style, as if a single developer wrote the code in one session. At the inception of a software project, a coding standard is established to ensure that all developers on the project are working in concert. When the software project incorporates existing source code, or when performing maintenance on an existing software system, the coding standard states how to deal with the existing code base.
"The readability of source code has a direct impact on how well a developer comprehends a software system. Code maintainability refers to how easily that software system can be changed to add new features, modify existing features, fix bugs, or improve performance. Although readability and maintainability are the result of many factors, one particular facet of software development upon which all developers have an influence is coding technique. One of the easiest methods to ensure a team of developers will yield quality code is to establish a coding standard, which is then enforced at routine code reviews".
sweref
161
161
In a team environment or group collaboration, the use of coding standards ensures uniform coding practices, reduces oversight errors, and the time spent in code reviews. When NASA software development work is outsourced to a supplier (see Topic 7.3 03 - Acquisition Guidance), having a set of coding standards in place helps to ensure that the code produced by the contractor meets quality requirements mandated by NASA in the NASA Software Assurance Standard, NASA STD 8739.8.
sweref
278
278
A coding standard document may be written as a general document that is independent of any project. Project-specific needs are then added as amendments to the document. Note there is an important difference between a coding style and a coding standard. A coding style specifies how you indent lines or employ tabs and spaces to make the code easier to read by the software development team. A coding standard, which often includes a coding style, goes beyond just how to name a variable. It tells you how that variable is to be treated and when it is to be used (and not used).
sweref
006
006
Use of these standards will help the developer avoid actions that are not a smart practice to get into. They may also restrict coding statements to language statements from national or international standards.
One way to tell the difference between a coding style element and a coding standard element is to compare the functionality of the resulting code if either element is removed or changed. For example, if the style element is not followed in the software work product, the code should still work exactly the same way, with exactly the same behavior and safety checks. However, if a coding standard element is removed or altered, it is likely that the the code's "safety" and/or functionality is changed. That is the difference between the two. A coding standard is obviously more important than a coding style.
sweref
326
326
How Coding Standards are Classified
Software coding standards are classified by language, usage, and severity levels. Language specific rules and best coding practices are determined by industry experts in that particular language. Usage types and severity levels are set by the user.
sweref
326
326
Coding standards should address (for all the languages used):
Code structure: Includes overall project layout (files, and so on), classes, resources, and other source file types.
Error handling: Describes how objects handle errors, reporting, and logging.
Using compiler-specific features not in the language standard."
sweref
077
077
The following items may be an integral part of the coding standard to the extent their implementation actually affects the outcome of the execution of the software. Otherwise they are part of the coding style.
Formatting: Includes the use of white space, indentation, and length of statement lines in code. Some standards might include, for example, common editor setup and handling for tabs versus spaces for indentation.
Naming conventions: Specifies how developers name their methods, classes, variables, events, and parameters.
Comments: An English description in the code that explains the logic of the code. (Quality code is usually self-documenting by default.) The use of quality commenting gives quality code better maintainability and easier understandability.
Adherence and Verification
Assuring the adherence of the developed software to the coding standards provides the greatest benefit when followed from software development inception to completion. Coding standards are selected at the start of the software development effort. Verification activities of the software work products (see SWE-028) include reviews, such as peer reviews and inspections (see SWE-087), and assessments of how the coding standards are used to develop the software work products. The use of automated tools for assessing adherence to standards at appropriate reviews, or even on a batch mode run overnight, will assist the project team in adherence and verification.
How to Interpret the "and/or" Phrase in the Requirements Statement
The "and/or" in the text of the requirement statement is meant for flexibility in tailoring the requirement to the needs of the project. In appropriate settings (e.g., less "critical") a subset of this list (the "or" in "and/or") would be sufficient and compliant. For human-rated applications, the project would want to cover each of the items (methods, standards, criteria) in the statement (the "and" in "and/or"; e.g., the use of Klockwork tool as part of the "method," MISRA-C (software development standard for the C programming language developed by MISRA (Motor Industry Software Reliability Association).) "standards," avoidance of the project's restricted language constructs "criteria," etc).
Additional guidance related to the planning and control of software coding standards, and where they may be used, may be found in the following related requirements in this Handbook:
Smaller projects may consider using previously developed/tailored coding methods, standards and guidelines, rather than developing their own. These standard applications may be available in the software Process Asset Libraries (PAL) of other Centers, if not available at the performing Center.
Div
id
tabs-5
5. Resources
refstable
toolstable
Div
id
tabs-6
6. Lessons Learned
The NASA Lessons Learned database contains the following lessons learned related to coding standards:
Software Design for Maintainability. Lesson Number 0838. NASA has long recognized that software maintenance is a large cost driver in its software systems. Early planning for maintenance, which includes the use of appropriate and consistent coding standards, coding styles, and software configuration management systems, helps hold down software maintenance costs over the software life cycle. The lessons learned citation given below provides additional information on this topic of coding standards.
sweref
526
526
.
Mars Pathfinder Flight Software Development Process (1997). Lesson Number 0590. The software developer should also recognize that there is benefit to using coding standards dedicated to the project at hand. As this set of lessons learned derived from the Mars Pathfinder project shows, even though the coding standards and styles were tailored for the project, maintaining the set of derived coding standards for future upgrades and improvements will assure cost control
sweref
510
510
.
Panel
The reader of this lessons learned can also derive the warning that use of tailored coding standards for a new project raises the potential for error if extensive reuse of software work products is anticipated.