Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.

Slides:



Advertisements
Similar presentations
1.00 Lecture 37 A Brief Look at C++: A Guide to Reading C++ Programs.
Advertisements

Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Programming Languages and Paradigms
Programming Languages and Paradigms The C Programming Language.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Coding Standards for Java An Introduction. Why Coding Standards are Important? Coding Standards lead to greater consistency within your code and the code.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Defining classes and methods Recitation – 09/(25,26)/2008 CS 180 Department of Computer Science, Purdue University.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
JavaScript, Third Edition
Examining the Code [Reading assignment: Chapter 6, pp ]
Review of C++ Programming Part II Sheng-Fang Huang.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
The Java Programming Language
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
CSE 1301 Lecture 4 Using Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
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.
Introduction to Exception Handling and Defensive Programming.
Beginning C++ Through Game Programming, Second Edition
1 SystemVerilog Enhancement Requests Daniel Schostak Principal Engineer February 26 th 2010.
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.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Programming Languages and Paradigms Imperative Programming.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Guidelines for a Language- Independent Convention Identify global variables –Use g_prefix –Exp: g_RunningTotal Identify module variables –Use m_prefix.
More C++ Features True object initialisation
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
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.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Introduction to Object-Oriented Programming Lesson 2.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Advanced BioPSE NCRR Programming Conventions and Standards J. Davison de St. Germain Chief Software Engineer SCI Institute December 2003 J.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Java Generics. Lecture Objectives To understand the objective of generic programming To be able to implement generic classes and methods To know the limitations.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
C++ LANGUAGE MULTIPLE CHOICE QUESTION SET-3
CSE3302 Programming Languages (notes continued)
Objectives In this chapter, you will:
Enumeration Type Data type: a set of values with a set of operations on them Enumeration type: a simple data type created by the programmer To define an.
Introduction to C++ Systems Programming.
Java Primer 1: Types, Classes and Operators
University of Central Florida COP 3330 Object Oriented Programming
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.
CS360 Windows Programming
AVG 24th 2015 ADVANCED c# - part 1.
Java Programming Language
Introduction to Classes and Objects
CMSC 202 Java Primer 2.
Java Programming Course
Coding practices For IT and Computing students 2014.
Chap 2. Identifiers, Keywords, and Types
SPL – PS1 Introduction to C++.
SPL – PS3 C++ Classes.
Presentation transcript:

Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same types as employed by the selected framework. 4.Do not use external API / libraries if the functionality is available in the selected framework.

Why Coding Standard? Code has to be -Readable -Well formed -Well commented -Well formatted -Well named -Self-consistent -Robust Disciplined coders achieve this by adhering to coding standards. Coding standards are specific to languages and frameworks, although there are some universal rules.

Naming Conventions 1.Use Pascal capitalization when naming types, global functions, and class members. 2.Use camel capitalization when naming local variables, function & method arguments. 3.Uppercase all preprocessor definitions (including types aliases and constants). 4.Use underscore to separate words in preprocessor definitions. 5.Use single-letter uppercase names for generic and template type parameters. 6.Use camel capitalization for template non-type parameters. 7.Prefix interface names with I. 8.Prefix MFC class names with C.

Naming Conventions, cont’d 9.Do not prefix managed class names with C or any other character. 10.Do not prefix user-defined type names. 11.Do not prefix user-defined type data member names. 12.Prefix MFC class data members with m_. 13.Prefix global variables with g_. 14.Never use Polish notation with managed and avoid Polish notation in unmanaged code. 15.Do not prefix managed class data member names with m_ or any other prefix. 16.Suffix subclass type with a name indicative of the base class if the subclass is derived from one of the following classes.

Naming Conventions, cont’d 17.Suffix delegate types with Handler. 18.Name event handlers as follows OnDelegateTypeLessHandler. 19.Use full words rather than abbreviations (unless using common abbreviations). 20.Do not combine more than three words in a name (unless shorter notation requires abbreviation or causes ambiguity). 21.Use only common single-letter variable names such as: -i, j, k for indexes -x, y, z for coordinates. 22.Name methods that perform an instance action with a single verb. 23.Name methods that perform a specific non-instance action with a verb-object combination. 24.Name methods that return a value as GetValue. 25.Never supply more than one output parameter. 26.Do not use namespace-qualified names, employ using namespace instead. 27.Use C++ built-in types rather than their System namespace equivalents.

Memory Allocation Rules 1.Always prefer static allocation to dynamic allocation. 2.Always use static buffers for data, which size has a manageable rigid upper bound. 3.Always check data size against the buffer size. 4.Never assume an arbitrary size limit for data that is in principle unlimited, use dynamic allocation in this case. 5.Always make classes dispose their allocated buffers on destruction. 6.Always check pointers for NULL before using them.

Class Instantiation Rules 1.Always use stack allocation to instantiate classes. 2.Always use local instances or references rather than pointers to represent class instances. 3.Always check class instance pointers for NULL before using them. 4.Whenever possible make initialize-from or create-from routines members of the class. 5.If an external initialize-from or create-from method is unavoidable use local stack allocation and rely on copy constructor to initialize an external instance with the local instance data.

Variable Usage Rules 1.Avoid global variables. 2.Define local variables as close as possible to the place of first use. 3.Always initialize local variables. 4.Store arguments of complex functional expressions in temporary variables. 5.Store return values of complex functional expressions in temporary variables.

Function Usage Rules 1.Never ignore function error codes. 2.Use executing braking rather than nested branching. 3.Do not use error codes, throw exceptions.

Flow Control Rules 1.Always provide default case in switch statements. 2.Do not fall through from one case statement to another. 3.Never use goto statement.

Constant Usage Rules 1.Never hardcode constants. 2.Avoid hard coding string literals that are presented to user. 3.Declare enumerations for variables with limited choice of values. 4.Declare enumeration types to be used in place of Boolean arguments for clarity. 5.Declare constants in managed classes as literals.

General Coding Rules 1.Never duplicate your code. 2.Never engage in cut and paste practice. 3.Document design decisions in common components. 4.Do not modify proven code. 5.Always test your changes.

Compiler Settings 1.Set compiler warnings to level 4. 2.Treat warnings as errors. 3.Always enable Code Analysis both for managed and C/C++ code.

Read Chapter 9 from my book.