SlideShare a Scribd company logo
CODE STANDARDS &
BEST PRACTICES

Md. Ibrahim Rashid [ irashid.com ]
Good Code Vs. Bad Code
Good Code Vs. Bad Code
    “The best applications are coded properly”
    This sounds like an obvious statement, but by
    „properly‟, I mean that the code not only does its
    job well, but is also easy to add to, maintain and
    debug.
Ask Yourself?
   Is your code well organized and maintainable?
   Is you code well documented?
General Practices
   Naming Conventions
   Indentation
   Brace Style
   Commenting
   Code consistency
   Readability Vs. Compression
What should coding standards
provide?
   File, class, variable naming conventions
   Code formatting conventions
   Guidelines for consistency across the code
   Uniformity
Naming Conventions
   Class names are MixedCase
       [ ex. MyClass ]
   Method names are camelCase
       [ ex. myMethod() ]
   Constants are ALL_CAPS
       [ MY_CONSTANT ]
   Properties and variables are camelCase
       [ ex. myMethod() ]
   Non-public class members are _underscorePrefixed
       [Ex. _myPrivateVariable ]
Various Conventions

Class names        MyClass
Method names       my_function()          myFunction()        MyFunction
Constants          MY_CONSTANT
Properties and     my_variable            myVariable
variables
Non-public class   _my_private_variable   _myPrivateVariabl
members                                   e
Filenames          MyFile.php             myFile.php          my_file.php
Class Filenames    ClassMyFile.php        classMyFile.php     class_my_file.p
                                                              hp

        Case insensitive : MyFile.php and myfile.php are same in
        windows
Example
Scenario 1
Scenario 2
Scenario 3
Senerio 4(!BAD Don‟t MIX)
Indentation
PHP(Drupal)       Wordpress(PHP)   C(K&R
                                   standard)
Use an indent of 2 Use real         Tab = 4
spaces, with no    tabs and not    spaces
tabs               spaces,
Indentation
Indentation
 Always Make
Proper Indent.
Indentation
   Use of Real Tabs, 4 space as Tabs, only
    spaces is
    controversial.
   It‟s because same source code loaded into
    different editors with distinct setting will not
    look alike.
   Use lines less than 80 characters.
Indentation
   Brace Style
Indentation
   Brace Style
Indentation
   Use of Real Tabs, 4 space as Tabs, only
    spaces is
    controversial.
   It‟s because same source code loaded into
    different editors with distinct setting will not
    look alike.
   Use lines less than 80 characters.
Indentation
Commenting
   Always try to put comments on your code.
Commenting
Commenting
Commenting
Self documenting code
   Use of Long Method Name that reflects the
    purpose of the method.
   Still It needs to be commented.
Code Readability




       Always try to make readable code.
Readability Vs. Compression




                   YES!! I saved lots of bytes. Code is now compact.




There are lots of tools for making code compact. You don‟t have to write in
unreadable compact form.
Code consistency
   Let a project has 3 members.
   They watch this slide very carefully , and
    realized the importance of coding standard &
    best practices.
   Now, they are told to do the project perfectly.
   Each members uses his/her coding convention
    and submitted the project.
   What will be the output ?
Code consistency
   Always use same standard throughout a
    project.
   All members of a project must choose a fixed
    convention before starting a project.
Learn from Others
   Don’t invent your own standard. All of the
    issues have already been debated to death
    by many others.
   Use an established standard
    •  Minimize politics by choosing an external
      standard
     • Choose a standard compatible with the libraries
      you use
     • Use the standard as a requirement when
      outsourcing
   Stick to the standard you establish, don‟t mix
How To Write Unmaintainable
                             Code
                                  Ensure a job for life ;-)

   Read This Site Carefully with negating every
    concept.
   http://thc.org/root/phun/unmaintain.html
References
   http://wiki.mozilla.org/WebDev:FrontendCodeStandards
   http://na.isobar.com/standards/
   http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming
    _Languages/C%2B%2B/Code/Style_Conventions
   http://en.wikipedia.org/wiki/Best_Coding_Practices
   http://codex.wordpress.org/WordPress_Coding_Standards
   http://drupal.org/coding-standards
   Java Code Conventions
   http://www.sitepoint.com/coding-standards/
   http://www.programming4scientists.com/2008/09/26/good-code-
    bad-code-an-example/
   http://thc.org/root/phun/unmaintain.html
Coding conventions
Coding conventions

More Related Content

PPTX
Coding standards
PPT
Clean code
PDF
C# conventions & good practices
PPTX
Typescript ppt
PDF
Standards For Java Coding
PDF
7 rules of simple and maintainable code
KEY
Clean Code
PPS
Coding Best Practices
Coding standards
Clean code
C# conventions & good practices
Typescript ppt
Standards For Java Coding
7 rules of simple and maintainable code
Clean Code
Coding Best Practices

What's hot (20)

PPT
Coding standard
PPTX
Coding standards for java
PDF
TypeScript - An Introduction
PPTX
Refactoring and code smells
PPT
Coding Standards & Best Practices for iOS/C#
PPT
TypeScript Presentation
PPTX
Software development best practices & coding guidelines
PDF
ES6 presentation
PPTX
Classes and Objects in C#
PPTX
Code review
KEY
Clean code and Code Smells
PPTX
Introduction To C#
PDF
Solid NodeJS with TypeScript, Jest & NestJS
PPTX
Unit Testing with Python
PPTX
Coding conventions
PPTX
Introducing type script
PPT
Node.js Basics
PPTX
Code refactoring
PDF
Effective testing with pytest
PDF
Clean code
Coding standard
Coding standards for java
TypeScript - An Introduction
Refactoring and code smells
Coding Standards & Best Practices for iOS/C#
TypeScript Presentation
Software development best practices & coding guidelines
ES6 presentation
Classes and Objects in C#
Code review
Clean code and Code Smells
Introduction To C#
Solid NodeJS with TypeScript, Jest & NestJS
Unit Testing with Python
Coding conventions
Introducing type script
Node.js Basics
Code refactoring
Effective testing with pytest
Clean code
Ad

Viewers also liked (20)

PPTX
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
PPTX
Codes and conventions of news programming
PDF
Why coding convention ?
PDF
적당한 스터디 발표자료 만들기
PDF
Drawing Standards & Conventions: Lecture 2
PDF
MISRA C Chairman - Device Developer Conference 2016
PPT
Codings Standards
PPT
PPTX
Android code convention
PDF
MISRA C – Recent developments and a road map to the future
PDF
Misra C Software Development Standard
PPTX
Coding standards
ODP
Drupal Best Practices
PDF
Standard java coding convention
PPTX
Understand codes, conventions, styles and structures
PPTX
Coding standards and guidelines
PPTX
Learning styles
PPTX
Codes & Conventions
PPS
Java Exception handling
PPTX
C# coding standards, good programming principles & refactoring
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
Codes and conventions of news programming
Why coding convention ?
적당한 스터디 발표자료 만들기
Drawing Standards & Conventions: Lecture 2
MISRA C Chairman - Device Developer Conference 2016
Codings Standards
Android code convention
MISRA C – Recent developments and a road map to the future
Misra C Software Development Standard
Coding standards
Drupal Best Practices
Standard java coding convention
Understand codes, conventions, styles and structures
Coding standards and guidelines
Learning styles
Codes & Conventions
Java Exception handling
C# coding standards, good programming principles & refactoring
Ad

Similar to Coding conventions (20)

PPTX
Writing High Quality Code in C#
PPTX
Best-Practices-for-Writing-Clean-Code.Presentation
PPT
Best practices in enterprise applications
PDF
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
PPTX
Writing Clean Code (Recommendations by Robert Martin)
PDF
Writing Readable Code
PDF
高品質軟體的基本動作 101 for NTHU
PPTX
Coding standard and coding guideline
PPTX
Back-2-Basics: .NET Coding Standards For The Real World
PPTX
Back-2-Basics: .NET Coding Standards For The Real World
PDF
33rd degree talk: open and automatic coding conventions with walkmod
PPT
Raya code quality guidelines - enhancing readability
PPTX
WordCamp Pune 2017- WordPress Coding standards
DOCX
csharp.docx
PDF
Agile_goa_2013_clean_code_tdd
PDF
In-Depth Guide On WordPress Coding Standards For PHP & HTML
PDF
Php Egypt Jan14
PPT
c-coding-standards-and-best-programming-practices.ppt
PDF
C# c# for beginners crash course master c# programming fast and easy today
PPTX
Tools and practices to help you deal with legacy code
Writing High Quality Code in C#
Best-Practices-for-Writing-Clean-Code.Presentation
Best practices in enterprise applications
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Writing Clean Code (Recommendations by Robert Martin)
Writing Readable Code
高品質軟體的基本動作 101 for NTHU
Coding standard and coding guideline
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
33rd degree talk: open and automatic coding conventions with walkmod
Raya code quality guidelines - enhancing readability
WordCamp Pune 2017- WordPress Coding standards
csharp.docx
Agile_goa_2013_clean_code_tdd
In-Depth Guide On WordPress Coding Standards For PHP & HTML
Php Egypt Jan14
c-coding-standards-and-best-programming-practices.ppt
C# c# for beginners crash course master c# programming fast and easy today
Tools and practices to help you deal with legacy code

Recently uploaded (20)

PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Trump Administration's workforce development strategy
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Lesson notes of climatology university.
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Cell Structure & Organelles in detailed.
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Types and Its function , kingdom of life
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
GDM (1) (1).pptx small presentation for students
Orientation - ARALprogram of Deped to the Parents.pptx
Trump Administration's workforce development strategy
Chinmaya Tiranga quiz Grand Finale.pdf
Anesthesia in Laparoscopic Surgery in India
human mycosis Human fungal infections are called human mycosis..pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial disease of the cardiovascular and lymphatic systems
Lesson notes of climatology university.
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Cell Structure & Organelles in detailed.
Module 4: Burden of Disease Tutorial Slides S2 2025
Weekly quiz Compilation Jan -July 25.pdf
VCE English Exam - Section C Student Revision Booklet
Cell Types and Its function , kingdom of life
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

Coding conventions

  • 1. CODE STANDARDS & BEST PRACTICES Md. Ibrahim Rashid [ irashid.com ]
  • 2. Good Code Vs. Bad Code
  • 3. Good Code Vs. Bad Code  “The best applications are coded properly”  This sounds like an obvious statement, but by „properly‟, I mean that the code not only does its job well, but is also easy to add to, maintain and debug.
  • 4. Ask Yourself?  Is your code well organized and maintainable?  Is you code well documented?
  • 5. General Practices  Naming Conventions  Indentation  Brace Style  Commenting  Code consistency  Readability Vs. Compression
  • 6. What should coding standards provide?  File, class, variable naming conventions  Code formatting conventions  Guidelines for consistency across the code  Uniformity
  • 7. Naming Conventions  Class names are MixedCase  [ ex. MyClass ]  Method names are camelCase  [ ex. myMethod() ]  Constants are ALL_CAPS  [ MY_CONSTANT ]  Properties and variables are camelCase  [ ex. myMethod() ]  Non-public class members are _underscorePrefixed  [Ex. _myPrivateVariable ]
  • 8. Various Conventions Class names MyClass Method names my_function() myFunction() MyFunction Constants MY_CONSTANT Properties and my_variable myVariable variables Non-public class _my_private_variable _myPrivateVariabl members e Filenames MyFile.php myFile.php my_file.php Class Filenames ClassMyFile.php classMyFile.php class_my_file.p hp Case insensitive : MyFile.php and myfile.php are same in windows
  • 14. Indentation PHP(Drupal) Wordpress(PHP) C(K&R standard) Use an indent of 2 Use real Tab = 4 spaces, with no tabs and not spaces tabs spaces,
  • 17. Indentation  Use of Real Tabs, 4 space as Tabs, only spaces is controversial.  It‟s because same source code loaded into different editors with distinct setting will not look alike.  Use lines less than 80 characters.
  • 18. Indentation  Brace Style
  • 19. Indentation  Brace Style
  • 20. Indentation  Use of Real Tabs, 4 space as Tabs, only spaces is controversial.  It‟s because same source code loaded into different editors with distinct setting will not look alike.  Use lines less than 80 characters.
  • 22. Commenting  Always try to put comments on your code.
  • 26. Self documenting code  Use of Long Method Name that reflects the purpose of the method.  Still It needs to be commented.
  • 27. Code Readability Always try to make readable code.
  • 28. Readability Vs. Compression YES!! I saved lots of bytes. Code is now compact. There are lots of tools for making code compact. You don‟t have to write in unreadable compact form.
  • 29. Code consistency  Let a project has 3 members.  They watch this slide very carefully , and realized the importance of coding standard & best practices.  Now, they are told to do the project perfectly.  Each members uses his/her coding convention and submitted the project.  What will be the output ?
  • 30. Code consistency  Always use same standard throughout a project.  All members of a project must choose a fixed convention before starting a project.
  • 31. Learn from Others  Don’t invent your own standard. All of the issues have already been debated to death by many others.  Use an established standard • Minimize politics by choosing an external standard  • Choose a standard compatible with the libraries you use  • Use the standard as a requirement when outsourcing  Stick to the standard you establish, don‟t mix
  • 32. How To Write Unmaintainable Code Ensure a job for life ;-)  Read This Site Carefully with negating every concept.  http://thc.org/root/phun/unmaintain.html
  • 33. References  http://wiki.mozilla.org/WebDev:FrontendCodeStandards  http://na.isobar.com/standards/  http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming _Languages/C%2B%2B/Code/Style_Conventions  http://en.wikipedia.org/wiki/Best_Coding_Practices  http://codex.wordpress.org/WordPress_Coding_Standards  http://drupal.org/coding-standards  Java Code Conventions  http://www.sitepoint.com/coding-standards/  http://www.programming4scientists.com/2008/09/26/good-code- bad-code-an-example/  http://thc.org/root/phun/unmaintain.html