SlideShare una empresa de Scribd logo
1 de 35
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

Más contenido relacionado

La actualidad más candente

Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Asim Rais Siddiqui
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practicesTan Tran
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelinesbrijraj_singh
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code PrinciplesYeurDreamin'
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java CodingRahul Bhutkar
 
Shell and its types in LINUX
Shell and its types in LINUXShell and its types in LINUX
Shell and its types in LINUXSHUBHA CHATURVEDI
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software CodingNikhil Pandit
 
Software engineering principles in system software design
Software engineering principles in system software designSoftware engineering principles in system software design
Software engineering principles in system software designTech_MX
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionsaber tabatabaee
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best PracticesTheo Jungeblut
 

La actualidad más candente (20)

Coding standards
Coding standardsCoding standards
Coding standards
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practices
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelines
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java Coding
 
Shell and its types in LINUX
Shell and its types in LINUXShell and its types in LINUX
Shell and its types in LINUX
 
Clean Code
Clean CodeClean Code
Clean Code
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software Coding
 
Software engineering principles in system software design
Software engineering principles in system software designSoftware engineering principles in system software design
Software engineering principles in system software design
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
Clean code
Clean code Clean code
Clean code
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Clean code
Clean codeClean code
Clean code
 
OOP java
OOP javaOOP java
OOP java
 

Destacado

Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...CS, NcState
 
Codes and conventions of news programming
Codes and conventions of news programming Codes and conventions of news programming
Codes and conventions of news programming joshutb
 
Why coding convention ?
Why coding convention ?Why coding convention ?
Why coding convention ?Panji Gautama
 
적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기종빈 오
 
Drawing Standards & Conventions: Lecture 2
Drawing Standards & Conventions: Lecture 2Drawing Standards & Conventions: Lecture 2
Drawing Standards & Conventions: Lecture 2Virtu Institute
 
MISRA C Chairman - Device Developer Conference 2016
MISRA C Chairman - Device Developer Conference 2016MISRA C Chairman - Device Developer Conference 2016
MISRA C Chairman - Device Developer Conference 2016Andrew Banks
 
MISRA C – Recent developments and a road map to the future
MISRA C – Recent developments and a road map to the futureMISRA C – Recent developments and a road map to the future
MISRA C – Recent developments and a road map to the futureAdaCore
 
Misra C Software Development Standard
Misra C Software Development StandardMisra C Software Development Standard
Misra C Software Development StandardVittorio Giovara
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Standard java coding convention
Standard java coding conventionStandard java coding convention
Standard java coding conventionTam Thanh
 
Understand codes, conventions, styles and structures
Understand codes, conventions, styles and structuresUnderstand codes, conventions, styles and structures
Understand codes, conventions, styles and structuresmattwako
 
Learning styles
Learning stylesLearning styles
Learning stylesaghchay
 
Codes & Conventions
Codes & ConventionsCodes & Conventions
Codes & Conventions954869
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Basics of Functional Neuroanatomy
Basics of Functional NeuroanatomyBasics of Functional Neuroanatomy
Basics of Functional NeuroanatomyVivek Misra
 

Destacado (18)

Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
 
Codes and conventions of news programming
Codes and conventions of news programming Codes and conventions of news programming
Codes and conventions of news programming
 
Why coding convention ?
Why coding convention ?Why coding convention ?
Why coding convention ?
 
적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기
 
Drawing Standards & Conventions: Lecture 2
Drawing Standards & Conventions: Lecture 2Drawing Standards & Conventions: Lecture 2
Drawing Standards & Conventions: Lecture 2
 
MISRA C Chairman - Device Developer Conference 2016
MISRA C Chairman - Device Developer Conference 2016MISRA C Chairman - Device Developer Conference 2016
MISRA C Chairman - Device Developer Conference 2016
 
Codings Standards
Codings StandardsCodings Standards
Codings Standards
 
Misra c
Misra cMisra c
Misra c
 
Android code convention
Android code conventionAndroid code convention
Android code convention
 
MISRA C – Recent developments and a road map to the future
MISRA C – Recent developments and a road map to the futureMISRA C – Recent developments and a road map to the future
MISRA C – Recent developments and a road map to the future
 
Misra C Software Development Standard
Misra C Software Development StandardMisra C Software Development Standard
Misra C Software Development Standard
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Standard java coding convention
Standard java coding conventionStandard java coding convention
Standard java coding convention
 
Understand codes, conventions, styles and structures
Understand codes, conventions, styles and structuresUnderstand codes, conventions, styles and structures
Understand codes, conventions, styles and structures
 
Learning styles
Learning stylesLearning styles
Learning styles
 
Codes & Conventions
Codes & ConventionsCodes & Conventions
Codes & Conventions
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Basics of Functional Neuroanatomy
Basics of Functional NeuroanatomyBasics of Functional Neuroanatomy
Basics of Functional Neuroanatomy
 

Similar a Coding conventions

Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#Svetlin Nakov
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Yasuko Ohba
 
Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Shirish Bari
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Codeeddiehaber
 
高品質軟體的基本動作 101 for NTHU
高品質軟體的基本動作 101 for NTHU高品質軟體的基本動作 101 for NTHU
高品質軟體的基本動作 101 for NTHUSu Jan
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmodwalkmod
 
Raya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readabilityRaya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readabilityAbdel Hady Muhammad
 
WordCamp Pune 2017- WordPress Coding standards
WordCamp Pune 2017- WordPress Coding standardsWordCamp Pune 2017- WordPress Coding standards
WordCamp Pune 2017- WordPress Coding standardsSwapnil Patil
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddSrinivasa GV
 
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLeSparkBiz
 
Php Egypt Jan14
Php Egypt Jan14Php Egypt Jan14
Php Egypt Jan14Hani Gamal
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptVinayakHospet1
 
C# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayC# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayAfonso Macedo
 
Tools and practices to help you deal with legacy code
Tools and practices to help you deal with legacy codeTools and practices to help you deal with legacy code
Tools and practices to help you deal with legacy codeDennis Doomen
 

Similar a Coding conventions (20)

Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#
 
Code review
Code reviewCode review
Code review
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
 
Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
高品質軟體的基本動作 101 for NTHU
高品質軟體的基本動作 101 for NTHU高品質軟體的基本動作 101 for NTHU
高品質軟體的基本動作 101 for NTHU
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-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
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod
 
Raya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readabilityRaya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readability
 
WordCamp Pune 2017- WordPress Coding standards
WordCamp Pune 2017- WordPress Coding standardsWordCamp Pune 2017- WordPress Coding standards
WordCamp Pune 2017- WordPress Coding standards
 
csharp.docx
csharp.docxcsharp.docx
csharp.docx
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tdd
 
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
 
Php Egypt Jan14
Php Egypt Jan14Php Egypt Jan14
Php Egypt Jan14
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.ppt
 
C# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayC# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy today
 
Tools and practices to help you deal with legacy code
Tools and practices to help you deal with legacy codeTools and practices to help you deal with legacy code
Tools and practices to help you deal with legacy code
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
 

Último

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 

Último (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 

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