CSCE-221 C++ Coding Standard/Guidelines

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Chapter 1: Computer Systems
Coding Standards for Java An Introduction. Why Coding Standards are Important? Coding Standards lead to greater consistency within your code and the code.
Documentation 1 Comprehending the present – Investing in the future.
1 Introduction to Software Engineering Lecture 42 – Communication Skills.
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
Chapter 2: Introduction to C++.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Programming Introduction to C++.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
Java Language and SW Dev’t
Good Programming Practices. 2 home back first prev next last What Will I Learn? List examples of good programming practices Accurately insert comments.
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
Sharda University P. K. Mishra (Asst.Prof) Department of Computer Science & Technology Subject Name: Programming Using C Sub Code: CSE-106 Programming.
Java Coding Standards and Best Practices Coding Standards Introduction: After completing this chapter, you will able to keep your code up to standards.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Code Conventions Tonga Institute of Higher Education.
Flow of Control and Program Style n Nested if statements n C++ struct n Program Style n Lab Exercise.
Documentation and Style. Documentation and Comments  Programs should be self-documenting.  Use meaningful variable names.  Use indentation and white.
Coding Conventions  Coding conventions are a set of guidelines for a specific software project that recommend programming style, practices and methods.
CPS120: Introduction to Computer Science Introduction to C++
Chapter 7 Implementation. Implementation Approaches F Big bang –Code entire system and test in an unstructured manner F Top-down –Start by implementing.
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.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Chapter Topics The Basics of a C++ Program Data Types
Working with Java.
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
ICS103 Programming in C Lecture 4: Data Types, Operators & Expressions
Lecture 3: Operators, Expressions and Type Conversion
Compilation and Debugging
Compilation and Debugging
Basic Elements of C++.
Objectives Identify the built-in data types in C++
Mr. Shaikh Amjad R. Asst. Prof in Dept. of Computer Sci. Mrs. K. S
Basic Elements of C++ Chapter 2.
Statements, Comments & Simple Arithmetic
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
Variables in C Topics Naming Variables Declaring Variables
Chapter 1: Computer Systems
Introduction to Classes and Objects
Variables in C Topics Naming Variables Declaring Variables
Documentation and Style
Anatomy of a Java Program
Chapter 2: Introduction to C++.
Topics Introduction to Functions Defining and Calling a Function
Programming Introduction to C++.
Predefined Functions Revisited
Chap 2. Identifiers, Keywords, and Types
Tonga Institute of Higher Education
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Lecture 8 Object Oriented Programming (OOP)
Programming Fundamental-1
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

CSCE-221 C++ Coding Standard/Guidelines Emil Thomas 01/24/19 Source : https://www.csee.umbc.edu/courses/undergraduate/341/fall16/projects/coding-standards.shtml

What is a coding standard A set of guidelines that recommend programming style, practices, and methods for each aspect of a program Usually covers Naming Conventions : Variable, Function , Class Names, File Names White spaces Indentation, Bracket Placement Comments etc. etc..

Why need Coding Standards? Help improve the readability of the source code  Make software maintenance easier Less Bugs Team Work Reduces the cost of maintenance Task Automation (helps the scripts to read code better)

File Naming For every project, a file named Driver.cpp containing only the main( ) function is required. Executable should be named driver.out All C++ classes are defined in a separate header file. File name should be Classname.h Implement only getters/setters in the header All C++ classes are implemented in a separate source code file File name should be Classname.cpp Implement all the other required functions here

Class Definition Standards All class names begin with uppercase Only one private, protected and public section in a class definition.  public comes first, followed by protected and then private. Class methods must have complete function header comments Except getters/setters Class methods must be const whenever possible Class data members name MAY begin with m_  int m_length;

Variable & Function Naming Use meaningful descriptive variable names float radius instead of float r; Use lowerCamel case for variables int numStudents instead of int num_of_students Function MAY begin names with uppercase letters GetName() or getName() function prototypes must include parameter names as well as types Default values for parameters must be specified in the prototype

Avoid Magic Numbers Constants/enum should be used for magic numbers and strings whenever possible const double PI = 3.14159

Indentation, Spacing Use blank lines to separate pieces of code for readability to separate unrelated sections of code Wrong Right

Indentation, Spacing Use a tab or 4 spaces for each level of indentation Use spaces around all operators. Wrong Right x=y+8; x = y + 8; If (x>y) {statement1;} else {statement 2;} If (x > y) { statement1; } else statement 2;

Discussion of bad1.cpp file

Braces Recommended Styles K & R Style Allman/BSD Style

Brace Usage Use a consistent style for braces Braces are required for single statement if/else/while/for structures Wrong Right

Discussion of bad2.cpp file

Comments Comments are the programmer's main source of documentation. Rule of Thumb: Approximately every 5 lines of code need AT LEAST 1 comment. Not every line of code needs a comment. Constant declarations MUST have 1 comment. Every cpp and .h file should contain File header comment Every function should contain function header comment.

File Header Comments EVERY .cpp and .h file should contain an opening comment describing the contents of the file And MUST include the following information. The file name The project number Your name The date the file was created Your section number Your tamu e-mail address A description of what the code in the file does

Function Header Comments Each FUNCTION and CLASS METHOD (Except getters/setters) must have a header comment that includes the following information The function's name The function's pre-condition(s) (if there are no pre-conditions, say so). The function's post-condition(s). Circle.h Circle.cpp

Inline Comments MUST appear above the code to which it applies and is indented to the same level as the code Wrong Right

Exercise(Handout) & Google Survey Questions?

References https://www.csee.umbc.edu/courses/undergraduate/341/fall16/proj ects/coding-standards.shtml https://en.wikipedia.org/wiki/Indentation_style http://www.cs.nott.ac.uk/~pszcah/G53QAT/Presentations09/jjb07u/ QAT09Presentations-jjb07u.ppt