CS 501 Lint Purify and Coding Standards Eric

  • Slides: 14
Download presentation
CS 501 Lint, Purify, and Coding Standards Eric Melin September 26, 1999

CS 501 Lint, Purify, and Coding Standards Eric Melin September 26, 1999

Lint " " " Lint is a semantic checker that identifies potential bugs in

Lint " " " Lint is a semantic checker that identifies potential bugs in C programs Lint is a mistake! In the early days of C on UNIX complete semantic checking was removed from the C compiler as a design decision. This allowed for smaller, simpler, and faster compilers at the expense of potentially buggy code. Lint exists on UNIX systems (but not LINUX) Most modern ANSI C compilers include Lint semantic checking functionality but only some of Lint’s other features Use Lint Early and Often!

What does Lint Do? " " " Checks for consistency in function use across

What does Lint Do? " " " Checks for consistency in function use across multiple files Finds � bugs � non-portable code � wasteful code Typical Bugs Detected include � Argument types transposed between function and call � Function with wrong number of arguments takes junk from stack � Variables being used before set or never used

More about Lint " " See Unix man page OR “Checking C Programs with

More about Lint " " See Unix man page OR “Checking C Programs with lint” By Ian F. Darwin

Purify " " " Purify is a tool for locating runtime errors in a

Purify " " " Purify is a tool for locating runtime errors in a C/C++ program Purify can find � Array bounds errors � Accesses through dangling pointers � Uninitialized memory reads � Memory allocation errors � Memory leaks Purify is available on Windows and UNIX systems and is a product of Rational Software www. rational. com

How Purify Works " " Purify instruments a program by adding protection instructions around

How Purify Works " " Purify instruments a program by adding protection instructions around every load and store operation When program is executed a viewer will be created to display errors as they happen Purify is flexible and can be run standalone with any executable (written in C) or within a debugging environment like Visual Studio Purify is customizable and can be set to ignore certain types of errors

How to Use Purify " " add purify command to link command program: $(OBJS)

How to Use Purify " " add purify command to link command program: $(OBJS) purify [-option. . . ] $(CC) $(CFLAGS) -o program $(OBJS) $(LIBS) OR run purify in Visual Studio OR load file in purify executable

Coding Standards " Why Have Coding Standards? � Greater consistency between multiple developers �

Coding Standards " Why Have Coding Standards? � Greater consistency between multiple developers � Easier to develop and maintain � Saves time and money " The Prime Directive " Document every time you go against a standard " No standard is perfect for every application, but failure to comply with your standards requires a comment

Ambler’s Law of Standards " " " Industry Standards > organizational standards > project

Ambler’s Law of Standards " " " Industry Standards > organizational standards > project standards > no standards The more commonly accepted a standard the easier it is for team members to communicate Invent standards when necessary, but don’t waste time creating something that you won’t be able to use later. All languages have recommended coding standards available. It is well worth your effort to find and use industry standards Push for organizational standards whenever possible

Good Coding Style " Names � Use full English descriptors � Use mixed case

Good Coding Style " Names � Use full English descriptors � Use mixed case to make names readable � Use abbreviations sparingly and consistently � Avoid long names � Avoid leading/trailing underscores " Documentation � Document the purpose of every variable � Document why something is done not just what

" Accessors � use get. Var() and set. Var() functions on all class variable

" Accessors � use get. Var() and set. Var() functions on all class variable unless class is being used solely as a data structure " Member Functions Documentation � What and why member function does what it does � Parameters / return value � How function modifies object � Preconditions /Postconditions � Concurrency issues � Restrictions " Internal Documentation � Control Structures � Why as well as what the code does � Difficult or complex code � Processing order

Examples of Coding Standards " http: //www. ambysoft. com/java. Coding. Standards. html " http:

Examples of Coding Standards " http: //www. ambysoft. com/java. Coding. Standards. html " http: //www. swtech. com/java/codestd/ " " http: //ccs. hst. nasa. gov/ccspages/policies/standards/c oding_standards. html http: //www. scriptics. com/doc/style. Guide. pdf