Introduction to Coding Standards Phil Pratt-Szeliga CSE 784 Fall 2009.

Slides:



Advertisements
Similar presentations
Validation checking and testing that your web pages function as intended.
Advertisements

Chapter 8 Technicalities: Functions, etc. Bjarne Stroustrup
CSE 105 Structured Programming Language (C)
Lecture 10 Methods COMP1681 / SE15 Introduction to Programming.
C Language.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Chapter 1: Computer Systems
CSE 222 Systems Programming Introduction Dr. Jim Holten.
Programming Style a programs language gives you a lot of freedom how to write a program – too much? but some programming style is good goal: it must be.
Introduction to Computers and Programming Class 6 Introduction to C Professor Avi Rosenfeld.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Introduction to C Topics Compilation Using the gcc Compiler
Java Programming, 3e Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Monday, Jan 13, 2003Kate Gregory with material from Deitel and Deitel Week 2 Questions from Last Week Control Structures Functions Lab 1.
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Style Guidelines. Why do we need style?  Good programming style helps promote the readability, clarity and comprehensibility of your code.
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Advanced Computer Science Lab Coding Style & Documentation.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
Documentation and Programming Style Appendix A © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
CSC 107 – Programming For Science. Announcements  Locations of Macs to use outside of lab time  Can find on Library ground floor (6) & main floor (6)
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  While at Bell Labs, created language to develop Unix 
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Monday, Jan 6, 2003Kate Gregory with material from Deitel and Deitel CO 204 Object Oriented Programming 2003 Trent University Kate Gregory.
Code Conventions Tonga Institute of Higher Education.
Documentation and Style. Documentation and Comments  Programs should be self-documenting.  Use meaningful variable names.  Use indentation and white.
CPS120: Introduction to Computer Science Introduction to C++
Chapter 9 Separate Compilation and Namespaces. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Separate Compilation (9.1)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation and Namespaces.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Problem Solving With C++ Doxygen Oct/Nov Introduction Doxygen is a documentation generator, a tool for writing software reference documentation.
Conditionals, Block Statements, Style
Introduction to C Topics Compilation Using the gcc Compiler
C++ First Steps.
UMBC CMSC 104 – Section 01, Fall 2016
Working with Java.
C Programming Hardik H. Maheta.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to C Topics Compilation Using the gcc Compiler
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Introduction to C Topics Compilation Using the gcc Compiler
Statements, Comments & Simple Arithmetic
Separate Compilation and Namespaces
Programming Vocabulary.
CSI-121 Structured Programming Language Lecture 14 Functions (Part 2)
2.1 Parts of a C++ Program.
Chapter 1: Computer Systems
CMSC 202 Java Primer 2.
Introduction to C Topics Compilation Using the gcc Compiler
Maintaining a Program In today’s lesson we will look at:
Documentation and Style
Introduction to C Topics Compilation Using the gcc Compiler
Controlling Program Flow
CSCE-221 C++ Coding Standard/Guidelines
Introduction to C Topics Compilation Using the gcc Compiler
Presentation transcript:

Introduction to Coding Standards Phil Pratt-Szeliga CSE 784 Fall 2009

Overview  Definitions  Motivation  Small Example Coding Standard  Conclusions  References

Definitions  A coding standard defines the style of your source code including (but not limited to): Indentation, Bracket Placement Variable, Function and Class Names Comments Declaring Pointers Higher level aspects (often to avoid obscure pitfalls) And more  A standard is defined for a language or project  If everyone follows the standard the code is easy to read

Motivation  A coding standard can be useful for the following reasons Programmers can quickly read someone else’s code on a project New people can get up to speed quickly People new to a language are spared the need to develop a personal style (adapted from reference #2)

Indentation and Bracket Placement Examples if (hours < 24 && minutes < 60 && seconds < 60) { return true; } else { return false; }  ANSI C++ Style

Indentation and Bracket Placement Examples if (hours < 24 && minutes < 60 && seconds < 60) { return true; } else { return false; }  Kernighan and Ritchie Style

Indentation and Bracket Placement Examples if ( hours< 24 && minutes< 60 && seconds< 60 ) {return true ;} else {return false ;}  Hopefully no one’s style

Indentation and Bracket Placement Example  Clearly we want to avoid the use the last option.  The coding standard can define that the last option shouldn’t happen  It also chooses between the two reasonable options This makes all the code on a project look the same

Commonly used Identifier Case  Upper Case with Underscores: THIS_IS_AN_EXAMPLE  Lower Camel Case: thisIsAnExample  Upper Camel Case: ThisIsAnExample  Lower Case with Underscores: this_is_an_example

Example Coding Standard – Variable Names  Classes have Upper Camel Case ex: PizzaFactory  Functions have lower Camel Case ex: myFunction  Member variables begin with m and have Upper Camel Case ex: mMemberVariable  Local variables have lower case with underscores ex: my_local_variable

Example Coding Standard – Indentation, Spaces and Tabs  No tabs are used, set your editor to enter spaces when you hit tab  When you hit tab, 2 spaces are entered  There is only one space between tokens  K&R Placement of braces if(condition) { basic_block } else { basic_block }

Example Coding Standard – Declaring Pointers  C codestyle int *z;  C++ codestyle int* z;  But what about two variables?  C codestyle int *z, *y;  C++ codestyle int* z, y; (y is an int, not a pointer in this case)

Example Higher Level Aspect  In C++ the order of initialization of member variables depends on the order they are declared in the header file  It won’t work if you write code that tries to initialize them in a different order class MyClass { int x; int y; }; MyClass::MyClass() : y(0), x(y) {}  In the coding standard it could be specified that you should order your initialization in the order of declaration New people to the language will appreciate it

Conclusions  Some employers or projects will require you to conform to the coding standard This may make life easier for you if you sometimes ask: “What is the best way to do it?”  When you join a project you can ask: “Is there a coding standard?”  The coding standard could be specified by referencing the project’s coding standard document in the “Process Requirements” section of the B-Spec.  If a coding standard is specified you should use a tool to automatically check the standard during qualification

Coding Standards on the Web  Coding conventions for languages ng_style#Coding_conventions_for_lang uages ng_style#Coding_conventions_for_lang uages  C,C++,C#,Java  Coding conventions for projects ng_style#Coding_conventions_for_proj ects ng_style#Coding_conventions_for_proj ects  Linux Kernel

References 1. mming_style 2. pCodingStandard.html#important 3. _Programming_Language_(book) 4. %2B_Programming/Code_Style