SlideShare a Scribd company logo
1 of 21
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

What's hot

Software testing
Software testingSoftware testing
Software testingthaneofife
 
White Box Testing
White Box TestingWhite Box Testing
White Box TestingAlisha Roy
 
10. Software testing overview
10. Software testing overview10. Software testing overview
10. Software testing overviewghayour abbas
 
9. Software Implementation
9. Software Implementation9. Software Implementation
9. Software Implementationghayour abbas
 
Learn Bug Reporting Techniques
Learn Bug Reporting TechniquesLearn Bug Reporting Techniques
Learn Bug Reporting TechniquesQA InfoTech
 
Software, Security, manual testing training in Chandigarh
Software, Security, manual testing training in Chandigarh          Software, Security, manual testing training in Chandigarh
Software, Security, manual testing training in Chandigarh tapsi sharma
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented TestingDamian T. Gordon
 
WHITE BOX & BLACK BOX TESTING IN DATABASE
WHITE BOX & BLACK BOXTESTING IN DATABASEWHITE BOX & BLACK BOXTESTING IN DATABASE
WHITE BOX & BLACK BOX TESTING IN DATABASESalman Memon
 
White box & Black box testing
White box & Black box testingWhite box & Black box testing
White box & Black box testingNitishMhaske1
 
Practical Software Testing Tools
Practical Software Testing ToolsPractical Software Testing Tools
Practical Software Testing ToolsDr Ganesh Iyer
 
Testing documents
Testing documentsTesting documents
Testing documentssuhasreddy1
 
White box testing
White box testing White box testing
White box testing Mani Kanth
 
White box testing
White box testingWhite box testing
White box testingAbdul Basit
 

What's hot (20)

Software testing
Software testingSoftware testing
Software testing
 
White Box Testing
White Box TestingWhite Box Testing
White Box Testing
 
White box testing
White box testingWhite box testing
White box testing
 
10. Software testing overview
10. Software testing overview10. Software testing overview
10. Software testing overview
 
9. Software Implementation
9. Software Implementation9. Software Implementation
9. Software Implementation
 
Learn Bug Reporting Techniques
Learn Bug Reporting TechniquesLearn Bug Reporting Techniques
Learn Bug Reporting Techniques
 
Software testing methods
Software testing methodsSoftware testing methods
Software testing methods
 
SECh1920
SECh1920SECh1920
SECh1920
 
Taxonomy for bugs
Taxonomy for bugsTaxonomy for bugs
Taxonomy for bugs
 
Software, Security, manual testing training in Chandigarh
Software, Security, manual testing training in Chandigarh          Software, Security, manual testing training in Chandigarh
Software, Security, manual testing training in Chandigarh
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented Testing
 
Stm unit1
Stm unit1Stm unit1
Stm unit1
 
WHITE BOX & BLACK BOX TESTING IN DATABASE
WHITE BOX & BLACK BOXTESTING IN DATABASEWHITE BOX & BLACK BOXTESTING IN DATABASE
WHITE BOX & BLACK BOX TESTING IN DATABASE
 
White box & Black box testing
White box & Black box testingWhite box & Black box testing
White box & Black box testing
 
Practical Software Testing Tools
Practical Software Testing ToolsPractical Software Testing Tools
Practical Software Testing Tools
 
Testing documents
Testing documentsTesting documents
Testing documents
 
SE2018_Lec 17_ Coding
SE2018_Lec 17_ CodingSE2018_Lec 17_ Coding
SE2018_Lec 17_ Coding
 
Manual testing
Manual testingManual testing
Manual testing
 
White box testing
White box testing White box testing
White box testing
 
White box testing
White box testingWhite box testing
White box testing
 

Viewers also liked

Intro to Software Engineering - Coding Standards
Intro to Software Engineering - Coding StandardsIntro to Software Engineering - Coding Standards
Intro to Software Engineering - Coding StandardsRadu_Negulescu
 
Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopBlackRabbitCoder
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelinesbrijraj_singh
 
User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15koolkampus
 
Coding and testing in Software Engineering
Coding and testing in Software EngineeringCoding and testing in Software Engineering
Coding and testing in Software EngineeringAbhay Vijay
 
Lecture 7 Software Engineering and Design User Interface Design
Lecture 7 Software Engineering and Design User Interface Design Lecture 7 Software Engineering and Design User Interface Design
Lecture 7 Software Engineering and Design User Interface Design op205
 
User interface design: definitions, processes and principles
User interface design: definitions, processes and principlesUser interface design: definitions, processes and principles
User interface design: definitions, processes and principlesDavid Little
 
Architecture design in software engineering
Architecture design in software engineeringArchitecture design in software engineering
Architecture design in software engineeringPreeti Mishra
 

Viewers also liked (8)

Intro to Software Engineering - Coding Standards
Intro to Software Engineering - Coding StandardsIntro to Software Engineering - Coding Standards
Intro to Software Engineering - Coding Standards
 
Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCop
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelines
 
User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15
 
Coding and testing in Software Engineering
Coding and testing in Software EngineeringCoding and testing in Software Engineering
Coding and testing in Software Engineering
 
Lecture 7 Software Engineering and Design User Interface Design
Lecture 7 Software Engineering and Design User Interface Design Lecture 7 Software Engineering and Design User Interface Design
Lecture 7 Software Engineering and Design User Interface Design
 
User interface design: definitions, processes and principles
User interface design: definitions, processes and principlesUser interface design: definitions, processes and principles
User interface design: definitions, processes and principles
 
Architecture design in software engineering
Architecture design in software engineeringArchitecture design in software engineering
Architecture design in software engineering
 

Similar to 09 coding standards_n_guidelines

Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guidelineDhananjaysinh Jhala
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2Knoldus Inc.
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Manoj Ellappan
 
The pragmatic programmer
The pragmatic programmerThe pragmatic programmer
The pragmatic programmerLeylimYaln
 
Real World Java Compatibility
Real World Java CompatibilityReal World Java Compatibility
Real World Java CompatibilityTim Ellison
 
11. Lecture 19 Code standards and review.ppt
11. Lecture 19 Code standards and review.ppt11. Lecture 19 Code standards and review.ppt
11. Lecture 19 Code standards and review.pptMaddalaSeshu
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecturekhushbu thakker
 

Similar to 09 coding standards_n_guidelines (20)

Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 
9-Coding.ppt
9-Coding.ppt9-Coding.ppt
9-Coding.ppt
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
SE2_Lec 18_ Coding
SE2_Lec 18_ CodingSE2_Lec 18_ Coding
SE2_Lec 18_ Coding
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
7-CodingAndUT.ppt
7-CodingAndUT.ppt7-CodingAndUT.ppt
7-CodingAndUT.ppt
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
The pragmatic programmer
The pragmatic programmerThe pragmatic programmer
The pragmatic programmer
 
Software Engineering CSE/IT.pptx
 Software Engineering CSE/IT.pptx Software Engineering CSE/IT.pptx
Software Engineering CSE/IT.pptx
 
Real World Java Compatibility
Real World Java CompatibilityReal World Java Compatibility
Real World Java Compatibility
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
11. Lecture 19 Code standards and review.ppt
11. Lecture 19 Code standards and review.ppt11. Lecture 19 Code standards and review.ppt
11. Lecture 19 Code standards and review.ppt
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
 
Clean code ch03
Clean code ch03Clean code ch03
Clean code ch03
 
Learn java theory presentation
Learn java theory presentationLearn java theory presentation
Learn java theory presentation
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecture
 

More from University of Computer Science and Technology

More from University of Computer Science and Technology (20)

Real time-embedded-system-lec-02
Real time-embedded-system-lec-02Real time-embedded-system-lec-02
Real time-embedded-system-lec-02
 
Real time-embedded-system-lec-06
Real time-embedded-system-lec-06Real time-embedded-system-lec-06
Real time-embedded-system-lec-06
 
Real time-embedded-system-lec-05
Real time-embedded-system-lec-05Real time-embedded-system-lec-05
Real time-embedded-system-lec-05
 
Real time-embedded-system-lec-04
Real time-embedded-system-lec-04Real time-embedded-system-lec-04
Real time-embedded-system-lec-04
 
Real time-embedded-system-lec-03
Real time-embedded-system-lec-03Real time-embedded-system-lec-03
Real time-embedded-system-lec-03
 
Real time-embedded-system-lec-02
Real time-embedded-system-lec-02Real time-embedded-system-lec-02
Real time-embedded-system-lec-02
 
Real time-embedded-system-lec-07
Real time-embedded-system-lec-07Real time-embedded-system-lec-07
Real time-embedded-system-lec-07
 
12 software maintenance
12 software maintenance12 software maintenance
12 software maintenance
 
11 software testing_strategy
11 software testing_strategy11 software testing_strategy
11 software testing_strategy
 
10 software testing_technique
10 software testing_technique10 software testing_technique
10 software testing_technique
 
08 component level_design
08 component level_design08 component level_design
08 component level_design
 
07 interface design
07 interface design07 interface design
07 interface design
 
06 architectural design_workout
06 architectural design_workout06 architectural design_workout
06 architectural design_workout
 
05 architectural design
05 architectural design05 architectural design
05 architectural design
 
04 design concepts_n_principles
04 design concepts_n_principles04 design concepts_n_principles
04 design concepts_n_principles
 
03 requirement engineering_process
03 requirement engineering_process03 requirement engineering_process
03 requirement engineering_process
 
02 software process_models
02 software process_models02 software process_models
02 software process_models
 
01 software engineering_aspects
01 software engineering_aspects01 software engineering_aspects
01 software engineering_aspects
 
14 software technical_metrics
14 software technical_metrics14 software technical_metrics
14 software technical_metrics
 
13 software metrics
13 software metrics13 software metrics
13 software metrics
 

Recently uploaded

Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 

Recently uploaded (20)

LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 

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