• Like
  • Save
09 coding standards_n_guidelines
Upcoming SlideShare
Loading in...5
×
 

09 coding standards_n_guidelines

on

  • 777 views

Principles of Software Engineering by Utpal Roy, Jadavpur University, Kolkata, India

Principles of Software Engineering by Utpal Roy, Jadavpur University, Kolkata, India

Statistics

Views

Total Views
777
Views on SlideShare
777
Embed Views
0

Actions

Likes
0
Downloads
14
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    09 coding standards_n_guidelines 09 coding standards_n_guidelines Presentation Transcript

    • CODING STANDARDS AND GUIDELINES CODING STANDARDS AND GUIDELINES Let’s Discuss The IDEAL Coding AttitudeJanuary 13, 2012 Made By Utpal Ray 1
    • CODING STANDARDS AND GUIDELINES CODING STANDARDS Coding is a step to implement the design of the software system. A program converts design intentions into an executable set of instruction, and achieves the specified goal of the software. The process is to write a program using suitable language. Our goal is to write a program that is easy to understand, test, modify and maintain.January 13, 2012 Made By Utpal Ray 2
    • CODING STANDARDS AND GUIDELINES PROGRAMMING STANDARDS AND PROCEDURES If a program is given to three coders (programmers) to write, you willget three different programs, achieving successfully the desired result.So each must careful in their coding. It is like traffic rules: they are to be followed for your own and otherssafety, and also for the convenience of all who are on the road. Coding standards are three types, namely Universal, which is common irrespective of system. Domain specific, which depends on particular platform like Windows, Linix, Solaris, AIX, Embedded System etc. Organization Specific. which depends upon where you are developing code like, Oracle, SUN, HP, IBM, CISCO etc.January 13, 2012 Made By Utpal Ray 3
    • CODING STANDARDS AND GUIDELINES Programming style standards Variable names should be mnemonic, clear and simple e.g. “largest” rather than “x”. Expressions should be clear and simple e.g.: abs (x) <=0.01” rather than “(x<0.01) and (x> -0.01)” Indentation and format Indent bodies of structured statements at least 3 spaces Leave blank lines between logically related groups of statements, after the declarations, and between functions. Wrap long lines at no more than 80 chars and indent the continued statement further than the beginning of that statement. Clearly delineate subprograms (procedures, functions, modules)January 13, 2012 Made By Utpal Ray 4
    • CODING STANDARDS AND GUIDELINES COMMENTING Program should begin with a preface stating: 1. Programmers name 2. Date written 3. Course and assignment number 4. A summary or description of functionality i.e. what the program does and a brief description of how to run it. 6. Any special instructions on how to run it. 5. Any known assumptions built into the programJanuary 13, 2012 Made By Utpal Ray 5
    • CODING STANDARDS AND GUIDELINES Special Source Code Structure static char rcsid[] = "$Id$"; /* $Log$ */January 13, 2012 Made By Utpal Ray 6
    • CODING STANDARDS AND GUIDELINES Program Robustness:1. Do not check for equality among real numbers2. Prevent the abnormal termination of a program due to input error, check for the validity of the data when appropriate.3. Programs should not be built around a specific data set, programs, unless otherwise stated, should work correctly for any reasonable test data set.4. Do not use GOTO statements. January 13, 2012 Made By Utpal Ray 7
    • CODING STANDARDS AND GUIDELINES I/O Behavior: All I/O should use a proper format 1. All real number output should be formatted in decimal form unless scientific notation is appropriate. 2. All input from the keyboard should be preceded by a prompt telling the user what format is expected. For example “, Please input the date in mm/dd/yy format”. 3. Label all output valuesJanuary 13, 2012 Made By Utpal Ray 8
    • CODING STANDARDS AND GUIDELINES Modules and modular program structure Module coherence: each module should correspond to one subtask in the overall algorithm to solve the problem. Module independence: each module should be independent .i.e it should be self-contained and it should perform its task successfully without needing to know the inner working of the calling module. Procedures or functions should , in general occupy at most 50 lines. Use appropriate parameters rather than global variables. Avoid side effects. Hide any information from the caller that it does not need. The default should be to hide information unless the caller actually needs it.January 13, 2012 Made By Utpal Ray 9
    • CODING STANDARDS AND GUIDELINES Programming GuidelinesAll programs have three main factors that need to be handled properly tomake a program efficient and effective for which it is written.These three factors are: 1. Algorithms How the problem gets solved in the program? 2. Control Structure How the branching (if-then-else) and looping (while-true) should be organized? 2. Data structures How the data should be organized? (local vs. global, individual variable vs. group of variables – data structure)January 13, 2012 Made By Utpal Ray 10
    • CODING STANDARDS AND GUIDELINES Indentation Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4). Line Length Avoid lines longer than 80 characters, since theyre not handled well by many terminals and tools. Wrapping Lines When an expression will not fit on a single line, break it according to these general principles: Break after a comma. Break before an operator. Prefer higher-level breaks to lower-level breaks. Align the new line with the beginning of the expression at the same level on the previous line. If the above rules lead to confusing code or to code thats squished up against the right margin, just indent 8 spaces instead.January 13, 2012 Made By Utpal Ray 11
    • CODING STANDARDS AND GUIDELINES EXAMPLE of Bad INDENTATION //DONT USE THIS INDENTATION if ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { doSomethingAboutIt(); }January 13, 2012 Made By Utpal Ray 12
    • CODING STANDARDS AND GUIDELINES EXAMPLE of Good INDENTATION if ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { doSomethingAboutIt(); } ORif ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { doSomethingAboutIt();}January 13, 2012 Made By Utpal Ray 13
    • CODING STANDARDS AND GUIDELINES Three acceptable ways to format ternary expressions: alpha = (aLongBooleanExpression) ? beta : gamma; alpha = (aLongBooleanExpression) ? Beta : gamma; alpha = (aLongBooleanExpression) ? Beta : gamma;January 13, 2012 Made By Utpal Ray 14
    • CODING STANDARDS AND GUIDELINES BLOCK COMMENT EXAMPLE/** Here is a block comment.*/Block comments can start with /*-, which is recognized by indent(1) asthe beginning of a block comment that should not be reformatted.Example:* Here is a block comment with some very special/*-** formatting that I want indent(1) to ignore.* one* two* three*/A block comment should be preceded by a blank line to set itapart from the rest of the code.January 13, 2012 Made By Utpal Ray 15
    • CODING STANDARDS AND GUIDELINES Perfect Declarations FormattingHow many Declaration Per Line?One declaration per line is recommended since it encouragescommenting.In other words,int level; // indentation levelint size; // size of tableis preferred overint level, size;Do not put different types on the same line. Example: int foo, fooarray[]; //WRONG!January 13, 2012 Made By Utpal Ray 16
    • CODING STANDARDS AND GUIDELINES Single Line Statements Each line should contain at most one statement. Example:argv++; // Correctargc--; // Correctargv++; argc--; // AVOID!January 13, 2012 Made By Utpal Ray 17
    • CODING STANDARDS AND GUIDELINES The correct form of if, if-else, if else-if else Statements if (condition) { if (condition) { statements; statements; } else { } statements; } if (condition) { statements; } else if (condition) { } else { statements; }January 13, 2012 Made By Utpal Ray 18
    • CODING STANDARDS AND GUIDELINES The correct form of for Statements for (initialization; condition; update) {When using the comma statements;operator in the }initialization or updateclause of a forstatement, avoid thecomplexity of usingmore than threevariables. for (initialization; condition; update);January 13, 2012 Made By Utpal Ray 19
    • CODING STANDARDS AND GUIDELINES The correct form of do-while Statements do { statements; } while (condition);January 13, 2012 Made By Utpal Ray 20
    • CODING STANDARDS AND GUIDELINES switch (condition) {The correct form ofswitch Statements case ABC: statements; /* falls through */ case DEF: statements; break; case XYZ: statements; break; default: statements; break; }January 13, 2012 Made By Utpal Ray 21