SlideShare a Scribd company logo
CODING STANDARDS AND GUIDELINES




                   CODING STANDARDS
                         AND
                      GUIDELINES


                            Let’s Discuss
                                 The
                        IDEAL Coding Attitude


January 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 will
get 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 others
safety, 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 program


January 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 numbers


2.       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 values




January 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 Guidelines




All programs have three main factors that need to be handled properly to
make 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 they're 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 that's 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

     //DON'T 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();
                   }

                                           OR


if ((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) as
the 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 it
apart from the rest of the code.
January 13, 2012       Made By Utpal Ray                                 15
CODING STANDARDS AND GUIDELINES
                     Perfect Declarations Formatting
How many Declaration Per Line?

One declaration per line is recommended since it encourages
commenting.

In other words,
int level; // indentation level
int size; // size of table
is preferred over

int 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++;             // Correct

argc--;            // Correct

argv++; 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 update
clause        of    a    for
statement, avoid the
complexity of using
more         than     three
variables.
                                               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 of
switch 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

More Related Content

PPT
Software Coding- Software Coding
PPT
Software coding &amp; testing, software engineering
PPT
Software coding and testing
PDF
Intro to Software Engineering - Software Testing
PPTX
Coding standards
PPT
documentation-testing.ppt
PPT
Coding
PPTX
Structural and functional testing
Software Coding- Software Coding
Software coding &amp; testing, software engineering
Software coding and testing
Intro to Software Engineering - Software Testing
Coding standards
documentation-testing.ppt
Coding
Structural and functional testing

What's hot (20)

PPT
Software testing
PPTX
White Box Testing
PPTX
White box testing
PDF
10. Software testing overview
PDF
9. Software Implementation
PDF
Learn Bug Reporting Techniques
PPTX
Software testing methods
PPT
SECh1920
PPT
Taxonomy for bugs
PDF
Software, Security, manual testing training in Chandigarh
PPTX
Python: Object-oriented Testing
PDF
Stm unit1
PPTX
WHITE BOX & BLACK BOX TESTING IN DATABASE
PPTX
White box & Black box testing
PPTX
Practical Software Testing Tools
DOC
Testing documents
PDF
SE2018_Lec 17_ Coding
DOC
Manual testing
PPTX
White box testing
PPT
White box testing
Software testing
White Box Testing
White box testing
10. Software testing overview
9. Software Implementation
Learn Bug Reporting Techniques
Software testing methods
SECh1920
Taxonomy for bugs
Software, Security, manual testing training in Chandigarh
Python: Object-oriented Testing
Stm unit1
WHITE BOX & BLACK BOX TESTING IN DATABASE
White box & Black box testing
Practical Software Testing Tools
Testing documents
SE2018_Lec 17_ Coding
Manual testing
White box testing
White box testing
Ad

Viewers also liked (8)

PDF
Intro to Software Engineering - Coding Standards
PPT
Automating C# Coding Standards using StyleCop and FxCop
PPTX
Coding standards and guidelines
PPT
User Interface Design in Software Engineering SE15
PPTX
Coding and testing in Software Engineering
PDF
Lecture 7 Software Engineering and Design User Interface Design
PPTX
User interface design: definitions, processes and principles
PPT
Architecture design in software engineering
Intro to Software Engineering - Coding Standards
Automating C# Coding Standards using StyleCop and FxCop
Coding standards and guidelines
User Interface Design in Software Engineering SE15
Coding and testing in Software Engineering
Lecture 7 Software Engineering and Design User Interface Design
User interface design: definitions, processes and principles
Architecture design in software engineering
Ad

Similar to 09 coding standards_n_guidelines (20)

PPTX
Coding standard and coding guideline
ODP
Clean Code - Part 2
PPT
Best practices in enterprise applications
PPT
9-Coding.ppt
PPTX
Clean Code
PDF
Software Craftmanship - Cours Polytech
PDF
SE2_Lec 18_ Coding
PPT
Intro To AOP
PPT
7-CodingAndUT.ppt
PPTX
Basic iOS Training with SWIFT - Part 1
PPTX
The pragmatic programmer
PPTX
Top 10 Expert Tips for Writing Clean & Maintainable Code in Laravel
PPTX
Software Engineering CSE/IT.pptx
PDF
Real World Java Compatibility
PPTX
Coding standards
PPTX
Coding conventions
PPT
11. Lecture 19 Code standards and review.ppt
PPTX
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
PPTX
Clean code ch03
PPTX
Learn java theory presentation
Coding standard and coding guideline
Clean Code - Part 2
Best practices in enterprise applications
9-Coding.ppt
Clean Code
Software Craftmanship - Cours Polytech
SE2_Lec 18_ Coding
Intro To AOP
7-CodingAndUT.ppt
Basic iOS Training with SWIFT - Part 1
The pragmatic programmer
Top 10 Expert Tips for Writing Clean & Maintainable Code in Laravel
Software Engineering CSE/IT.pptx
Real World Java Compatibility
Coding standards
Coding conventions
11. Lecture 19 Code standards and review.ppt
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
Clean code ch03
Learn java theory presentation

More from University of Computer Science and Technology (20)

PPT
Real time-embedded-system-lec-02
PPT
Real time-embedded-system-lec-06
PPT
Real time-embedded-system-lec-05
PPT
Real time-embedded-system-lec-04
PPT
Real time-embedded-system-lec-03
PPT
Real time-embedded-system-lec-02
PPT
Real time-embedded-system-lec-07
PPTX
11 software testing_strategy
PPTX
10 software testing_technique
PPTX
PPTX
06 architectural design_workout
PPTX
04 design concepts_n_principles
PPTX
03 requirement engineering_process
PPTX
PPTX
01 software engineering_aspects
PPTX
14 software technical_metrics
Real time-embedded-system-lec-02
Real time-embedded-system-lec-06
Real time-embedded-system-lec-05
Real time-embedded-system-lec-04
Real time-embedded-system-lec-03
Real time-embedded-system-lec-02
Real time-embedded-system-lec-07
11 software testing_strategy
10 software testing_technique
06 architectural design_workout
04 design concepts_n_principles
03 requirement engineering_process
01 software engineering_aspects
14 software technical_metrics

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
01-Introduction-to-Information-Management.pdf
PPTX
master seminar digital applications in india
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Trump Administration's workforce development strategy
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Lesson notes of climatology university.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Classroom Observation Tools for Teachers
Microbial diseases, their pathogenesis and prophylaxis
01-Introduction-to-Information-Management.pdf
master seminar digital applications in india
Anesthesia in Laparoscopic Surgery in India
Module 4: Burden of Disease Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
Cell Types and Its function , kingdom of life
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Trump Administration's workforce development strategy
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
A systematic review of self-coping strategies used by university students to ...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Lesson notes of climatology university.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Yogi Goddess Pres Conference Studio Updates
Supply Chain Operations Speaking Notes -ICLT Program
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3

09 coding standards_n_guidelines

  • 1. CODING STANDARDS AND GUIDELINES CODING STANDARDS AND GUIDELINES Let’s Discuss The IDEAL Coding Attitude January 13, 2012 Made By Utpal Ray 1
  • 2. 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
  • 3. CODING STANDARDS AND GUIDELINES PROGRAMMING STANDARDS AND PROCEDURES If a program is given to three coders (programmers) to write, you will get 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 others safety, 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
  • 4. 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
  • 5. 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 program January 13, 2012 Made By Utpal Ray 5
  • 6. CODING STANDARDS AND GUIDELINES Special Source Code Structure static char rcsid[] = "$Id$"; /* $Log$ */ January 13, 2012 Made By Utpal Ray 6
  • 7. CODING STANDARDS AND GUIDELINES Program Robustness: 1. Do not check for equality among real numbers 2. 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
  • 8. 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 values January 13, 2012 Made By Utpal Ray 8
  • 9. 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
  • 10. CODING STANDARDS AND GUIDELINES Programming Guidelines All programs have three main factors that need to be handled properly to make 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
  • 11. 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 they're 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 that's squished up against the right margin, just indent 8 spaces instead. January 13, 2012 Made By Utpal Ray 11
  • 12. CODING STANDARDS AND GUIDELINES EXAMPLE of Bad INDENTATION //DON'T USE THIS INDENTATION if ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { doSomethingAboutIt(); } January 13, 2012 Made By Utpal Ray 12
  • 13. CODING STANDARDS AND GUIDELINES EXAMPLE of Good INDENTATION if ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { doSomethingAboutIt(); } OR if ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { doSomethingAboutIt(); } January 13, 2012 Made By Utpal Ray 13
  • 14. 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
  • 15. CODING STANDARDS AND GUIDELINES BLOCK COMMENT EXAMPLE /* * Here is a block comment. */ Block comments can start with /*-, which is recognized by indent(1) as the 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 it apart from the rest of the code. January 13, 2012 Made By Utpal Ray 15
  • 16. CODING STANDARDS AND GUIDELINES Perfect Declarations Formatting How many Declaration Per Line? One declaration per line is recommended since it encourages commenting. In other words, int level; // indentation level int size; // size of table is preferred over int level, size; Do not put different types on the same line. Example: int foo, fooarray[]; //WRONG! January 13, 2012 Made By Utpal Ray 16
  • 17. CODING STANDARDS AND GUIDELINES Single Line Statements Each line should contain at most one statement. Example: argv++; // Correct argc--; // Correct argv++; argc--; // AVOID! January 13, 2012 Made By Utpal Ray 17
  • 18. 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
  • 19. CODING STANDARDS AND GUIDELINES The correct form of for Statements for (initialization; condition; update) { When using the comma statements; operator in the } initialization or update clause of a for statement, avoid the complexity of using more than three variables. for (initialization; condition; update); January 13, 2012 Made By Utpal Ray 19
  • 20. CODING STANDARDS AND GUIDELINES The correct form of do-while Statements do { statements; } while (condition); January 13, 2012 Made By Utpal Ray 20
  • 21. CODING STANDARDS AND GUIDELINES switch (condition) { The correct form of switch 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