Chapter 6 examining the code

Source: Internet
Author: User
Tags coding standards

Examining the code
Chapter 6

Scenarios
Military
Financial
Factory Automation
Medical Software
Disciplined Development Model

Highlights
The benefits of static white-box testing
The different types of static white-box reviews
Coding guidelines and standards
How to generically review code for errors

Static white-box testing: Examining
The Design and code
Review: static testing and Dynamic Testing
Static white-box testing
Process of carefully and methodically reviewing
Software design, architecture or code for bugs
Executing it
Structural Analysis
Find bugs early and find bugs that wocould be difficult
To uncover or isolate with Dynamic black box testing
Side benefit: give black-box tester ideas for test
Cases to apply

Formal reviews
Four Essential Elements
Identify problems
Be directed to the design or code, not the person
Created it
Follow rules
Amount, time, and comment
Prepare
Know duties and responsibilities
Write a report
Summarizing the results of the review

Formal Review (2)
A few indirect results of formal review:
Communications
Black-box tester --- where problems may lie
Inexperienced programmers --- learn new techniques
Management --- better feel
Quality
More careful work attitude for programmers
Team camaraderie
Build respect to each other's skills and to be better
Understand each other's jobs and job needs
Solutions
Solutions may be found for tough problems

Peer reviews
Easiest way
Least formal method
People
The programmer who designs the architecture or
Wrote the code and one or two other programmers or
Testers acting as reviewers
Action
Review the Code together and looks for problems and
Oversights
Don't turn it into a coffee break
Make sure the four key elements are in place
Better than nothing

Walkthroughs
Up in formality from peer reviews
People
Programmer who wrote the code
Formally presents it to a small group of five or so other
Programmers and testers
Action
Receive copies in advance and get preparation
Presenter reads through and explain
Ask at the review
Presenter writes a report about bugs and Solutions
At least one Senior Programmer as reviewer

Inspections
Most formal type of review
People
Presenter or reader
Isn' t the original programmer
Forces some else to learn and understand
Different slant and interpretation
Inspector
Act as different roles (user, tester or product support
Team)
Different views reveals different bugs
Even backward inspector
Modulator and recorder
Assure the rule
Assure the specified tiveness

Inspections (2)
Do
Inspection meeting;
Programmer makes change;
Moderator verifies change;
While (inspection result = false or critical level
= High)

Coding standards and guidelines
Classic bugs
Something just won't work as written
Careful analysis by senior programmers and testers
Code may operate properly but may not be written
Meet a specific standard or guidelines
Grammatical and syntactical rules
Established, fixed, have-to-follow rules
Best Practice
National and international standards
Why change the workable and stable software?
Reliability
Readability/maintainability
Portability

Example of programming standards
And guidelines
Standard about using Goto, while, And if-else in C
Language
Four main parts of the Standard
Title
Standard
What's allow and not allowed
Justification
Example
Simple programming example
The differentiating factor is style
Even style cocould possibly become company Standard

Obtaining Standard
American National Standards Institute (ANSI)
Http://www.ansi.org
International Engineering Consortium (IEC)
Http://www.iec.org
International Organization for Standardization (ISO)
Http://www.iso.ch
National Committee for Information Technology
Standards (ncits)
Http://www.ncits.org
Some best practice in the Industrial
Your companies 'own standards

Generic Code review checklist
Checklist
Covers some problems you shoshould look
You must have some programming
Experience
Get your hand dirty

Data Reference errors
Bugs caused by improperly using variable, constant, array,
String or record
Is an uninitialized variable referenced? Looking
Omissions is just as important as looking for errors
Are array and string subscripts integer values and are they
Always within the bounds of the array's or string's dimension
Are there any potential "off by one" errors in Indexing
Operations or subscript references to Arrays
Is a variable used where a constant wocould actually work
Better
Is a variable ever assigned a value that's of a different type
Than the variable?
Is memory allocated for referenced pointers?
If a data structure is referenced in multiple functions or
Subroutines, is the structure defined identically in each one?

Data declaration Error
Bugs caused by improperly declaring or usng
Variables or constants
Are all variables assigned the correct length, type, and
Storage Class?
If a variable is initialized at the same time as it's
Declared, is it properly initialized and consistent with its
Type?
Are there any variables with similar names?
Are any variables declared that are never referenced
Or are referenced only once?
Are all the variables explicitly declared within their
Specific module? Or higher module?

Computation errors
Bad math
Do any calculations that use variables have different data types?
Do any calculations that use variables have the same data type but are
Different lengths?
Are the compiler's conversion rules for variables or inconsistent type or
Length understood and taken into account?
Is the target variable of an assignment smaller than the right-hand
Expression?
Is overflow or underflow in the middle of a numeric calculation possible?
Is it ever possible for a divisor/modulus to be zero?
In case of integer arithmetic, result in loss of precision?
Can a variable's value go outside its meaningful range?
For expressions containing multiple operators, is there any confusion
About the order of evaluation and is operator precedence correct? Are
Parentheses needed for clarification?

Comparison errors
Susceptible to boundary condition problems
Are the comparison correct?
<Or <=
Are there comparison between fractional or floatingpoint
Value?
Does each Boolean expression state what it shoshould
Sate? Does the Boolean calculation work as expected?
Is there any doubt about the order of evaluation?
Are the operands of A boolean operator Boolean?
Especially in language like C

Control Flow errors
Usually caused directly or indirectly
Computational or comparison errors
Are the end explicit and do they match?
Will the block eventually terminate?
Possibility of premature loop exit?
Possibility that a loop never executes?
Can index variable ever exceed the number
Branch possibilities like switch?
Are there any "off by one" errors that wowould
Cause unexpected flow through the loop?

Subroutine parameter errors
Due to incorrect passing of data to and from subroutines
Do the types and sizes of parameters specified ed match by
Calling order?
If a subroutine has multiple entry points, is a parameter ever
Referenced That isn' t associated with the current point
Entry?
If constants are ever passed as arguments, are they
Accidentally changed in the subroutine?
Does a subroutine alter a parameter that's intended only
Input value?
Do the units of each parameter match the units of each
Corresponding argument?
If global variable are present, do they have similar definitions
And attributes in all referencing subroutines?

Input/output errors
Does software strictly adhere to the specified format
Of the data being read or written by the external
Device?
If the file or peripheral isn't present or ready, is that
Error condtion handled?
Does the software handle the situation of the external
Device being disconnected, not available, or full
During a read or write?
Are all conceivable errors handled by the software in
An expected way?
Have all error messages been checked
Correctness, appropriateness, grammar, and spelling?

Other checks
Language issue?
Portable issue?
Compatibility?
Compilation?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.