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

La actualidad más candente (20)

Coding standards
Coding standardsCoding standards
Coding standards
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Writing clean and maintainable code
Writing clean and maintainable codeWriting clean and maintainable code
Writing clean and maintainable code
 
Java Notes
Java NotesJava Notes
Java Notes
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Clean code
Clean codeClean code
Clean code
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Name
 
Java Docs
Java DocsJava Docs
Java Docs
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Collections in-csharp
Collections in-csharpCollections in-csharp
Collections in-csharp
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
What is Dictionary In Python? Python Dictionary Tutorial | EdurekaWhat is Dictionary In Python? Python Dictionary Tutorial | Edureka
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
 

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
 
적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기적당한 스터디 발표자료 만들기
적당한 스터디 발표자료 만들기종빈 오
 
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
 
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
 
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
 
Basics of Functional Neuroanatomy
Basics of Functional NeuroanatomyBasics of Functional Neuroanatomy
Basics of Functional NeuroanatomyVivek Misra
 

Destacado (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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 

Último

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 

Último (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

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