Advanced BioPSE NCRR Programming Conventions and Standards J. Davison de St. Germain Chief Software Engineer SCI Institute 801-581-4078 December 2003 J.

Slides:



Advertisements
Similar presentations
Introduction to C++ Templates Speaker: Bill Chapman, C++ developer, financial company in Mid-Manhattan. Can be reached via: ' This.
Advertisements

A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
C++ Programming Languages
Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
C++ Basics Variables, Identifiers, Assignments, Input/Output.
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Templates. Class templates – why? Writing programs we often use abstract data types such as stack, queue or tree. Implementations of these types may be.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Basic Elements of C++ Chapter 2.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
CSE 333 – SECTION 4. Overview Pointers vs. references Const Classes, constructors, new, delete, etc. More operator overloading.
Pointer Data Type and Pointer Variables
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
The Rest of the Story.  Constructors  Compiler-generated  The Initializer List  Copy Constructors  Single-arg (conversion ctors)  The Assignment.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
CS212: Object Oriented Analysis and Design Lecture 10: Copy constructor.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
#include guards Practical session #2 Software Engineering
Data Types Declarations Expressions Data storage C++ Basics.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Object Oriented Programming Lecture 2: BallWorld.
Working with Java.
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
C Basics.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Variables, Identifiers, Assignments, Input/Output
C++ Compilation Model C++ is a compiled language
Programming Language C Language.
Java Programming Language
Operator Overloading; String and Array Objects
Chap 2. Identifiers, Keywords, and Types
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Presentation transcript:

Advanced BioPSE NCRR Programming Conventions and Standards J. Davison de St. Germain Chief Software Engineer SCI Institute December 2003 J. Davison de St. Germain Chief Software Engineer SCI Institute December 2003

Advanced BioPSE NCRR Coding Tools CVS - Concurrent Versions System - Check in/out code regularly to make sure everyone is working on the newest code base Regression Tester - Fix regression tester errors as soon as possible Coding Standards - See following pages

Advanced BioPSE NCRR Required 1. All code and comments are to be written in English. 2. All files must include appropriate license information. 3. Use the C++ mode in GNU Emacs and sci-c++-style.el to format code. 4. Include files in C++ always have the file name extension.h. 5. Implementation files in C++ always have the file name extension.cc. 6. Every include file must contain a “guard” that prevents multiple inclusions of the file, for example: #ifndef Geometry_BBox_h #define Geometry_BBox_h // Code... #endif // Geometry_BBox_h The name of the guard should be of the following form: libraryname _ filename_h

Advanced BioPSE NCRR Required (cont) 7.Use forward declarations wherever possible as opposed to including full definitions for classes, functions, and data: // Class class PointToMe; // Function void my_function(PointToMe &p, PointToMe *ptm); // Data PointToMe *m; 8. The names of variables and functions will begin with a lowercase letter and include underscore word separators. Names of constants should be in all CAPITALS, with underscore word separation: static int CONSTANT_INT_FIVE = 5; void my_function_name(); int my_local_variable_name = 0; 9.The names of class member variables are to end with an underscore, “_”: class MyClass{ int count_; };

Advanced BioPSE NCRR Required (cont) 10. The names of abstract data types (eg: Classes), and structs are to begin with an uppercase letter and each new word in the name should also be capitalized. class MyNewClassName { //... }; 11. Declare as const a member function that does not change the state of an object. 12. Constants are to be defined using const or enum. Never use #define to create constants. 13. A class which uses new to allocate instances managed by the class must define a copy constructor and an assignment operator. 14. All classes which are used as base classes and which have virtual functions, must define a virtual destructor. 15. Always use delete[] to deallocate arrays. 16. Use exception handling to trap errors (although exceptions should only be used for trapping truly exceptional events). Our exception model includes two levels of exceptions. The top level of exceptions are defined in Classlib/Exceptions.h and are thrown when a class specific exception is not appropriate. The bottom level of exceptions are class specific, defined in the class that throws them, and are subclassed off of the top level exceptions. These class specific exceptions are exceptions that can be caught and handled from the calling function (1 level above the class.) However, if the calling function chooses not to (or cannot) handle the class specific exception, the exception will propagate to the next level at which point it can be trapped and handled in the form of a top level exception. An example of a class specific exception would be a StackUnderFlowException for a stack class.

Advanced BioPSE NCRR Required (cont) 17. Comments should support generated documentation format. Comments in declarations should be of the form: //! … or /*! … */ These comments will then be visible in our online documentation. Comments in the definition part of your code need not have the !, as all the code is visible online including comments. Create comments that help the reader navigate your code. Comments should help the reader find the area of code he/she is looking for quickly. 18. Do not use identifiers which begin with one ('_') or two ('__') underscores. 19. Never use the $Id or $Log cvs directives. This confuses merging between branches. 20. Do not use #define to obtain more efficient code — use inline functions instead. 21. Avoid the use of numeric values in code; use symbolic values instead. This applies to numeric values that are repeated within the code but represent the same value. Eg: MAX_ARRAY_SIZE = Do not compare a pointer to NULL or assign NULL to a pointer; use 0 instead. 23. Avoid explicit type conversions (casts). If you must cast use dynamic_cast and insert a comment explaining why.

Advanced BioPSE NCRR Required (cont) 24. Never convert a constant to a non-constant. Use mutable if necesary. However, be aware of the thread safety problems this causes. 25. Never use goto. 26. Do not use malloc, realloc, or free.

Advanced BioPSE NCRR Recommended 1. ?Never? use more than 80 columns per line. 2. An include file for a class should have a file name of the form class name.h. Use uppercase and lowercase letters in the same way as in the source code. 3. Never include /usr/include/*.h, for example iostream.h in any header file. This causes a huge amount of code to be recursively included and needlessly compiled. Use forward declarations to avoid this 4. Group local includes together, then group system includes together. 5. Avoid global data if possible. 6. Optimize code only if you know that you have a performance problem. Think twice before you begin. 7. Always force your compiler to compile with the maximum warning setting, and before you check in code, fix all warnings. 8. Place machine-dependent code in a special file so that it may be easily located when porting code from one machine to another. 9. Encapsulate global variables and constants, enumerated types, and typedefs in a class. 10. Functions in general should not be more than 25 lines long. If you find this situation, break the function into several smaller functions. 11. If a function stores a pointer to an object which is accessed via an argument, let the argument have the type pointer. Use reference arguments in other cases.

Advanced BioPSE NCRR Recommended (cont) 12. When overloading functions, all variations should have the same semantics (be used for the same purpose). 13. Do not assume that you know how the invocation mechanism for a function is implemented. 14. Do not assume that an object is initialized in any special order in constructors. 15. Do not assume that static objects are initialized in any special order. 16. Use a typedef to simplify program syntax when declaring function pointers, or templated types. 17. When two operators are opposites (such as == and !=), it is appropriate to define both. 18. Use constant references ( const & ) instead of call-by-value, unless using a pre-defined data type or a pointer. 19. Minimize the number of temporary objects that are created as return values from functions or as arguments to functions. 20. Do not write code which is dependent on the lifetime of a temporary object. 21. Do not assume that the operands in an expression are evaluated in a definite order. Use parenthesis to enforce an order.

Advanced BioPSE NCRR Recommended (cont) 22. Use parentheses to clarify the order of evaluation for operators in expressions. 23. Avoid using shift operations instead of arithmetic operations. 24. Use cout instead of printf. 25. Do not assume that an int and a long have the same size. 26. Do not assume that pointers and integers have the same size. 27. Do not assume that longs, floats, doubles or long doubles may begin at arbitrary addresses. 28. Avoid pointer arithmetic. 29. Always use plain char if 8-bit ASCII is used. Otherwise, use signed char or unsigned char. 30. Do not assume that a char is signed or unsigned. 31. Do not depend on underflow or overflow functioning in any special way.

Advanced BioPSE NCRR Questions?

Advanced BioPSE NCRR

Advanced BioPSE NCRR