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

More Related Content

What's hot

Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practicesTan Tran
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringEyob Lube
 
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
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#Pascal Laurin
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaMadishetty Prathibha
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Namenahid035
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSSAmit Tyagi
 
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Propertieshstryk
 

What's hot (20)

Coding standards
Coding standardsCoding standards
Coding standards
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practices
 
Clean Code
Clean CodeClean Code
Clean Code
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoring
 
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
 
Code Review
Code ReviewCode Review
Code Review
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
Clean code
Clean codeClean code
Clean code
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
C# basics
 C# basics C# basics
C# basics
 
How java differs from c and c++
How java differs from c and c++How java differs from c and c++
How java differs from c and c++
 
Clean code
Clean codeClean code
Clean code
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Name
 
Clean code
Clean code Clean code
Clean code
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
css.ppt
css.pptcss.ppt
css.ppt
 
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Properties
 

Viewers also liked

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
 
적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기종빈 오
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java CodingRahul Bhutkar
 
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
 
Coding standards
Coding standardsCoding standards
Coding standardsMimoh Ojha
 
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
 

Viewers also liked (20)

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 ?
 
적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java Coding
 
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
 
Coding standards
Coding standardsCoding standards
Coding standards
 
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 to 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
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guidelineDhananjaysinh Jhala
 
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
 

Similar to 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
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
 
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
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
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
 

Recently uploaded

Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
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
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
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
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
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
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 

Recently uploaded (20)

Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.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
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
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
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
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
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
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Ă...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.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