Your SlideShare is downloading. ×
0
CODE STANDARDS &BEST PRACTICESMd. 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   ...
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....
What should coding standardsprovide?   File, class, variable naming conventions   Code formatting conventions   Guideli...
Naming Conventions   Class names are MixedCase       [ ex. MyClass ]   Method names are camelCase       [ ex. myMethod...
Various ConventionsClass names        MyClassMethod names       my_function()          myFunction()        MyFunctionConst...
Example
Scenario 1
Scenario 2
Scenario 3
Senerio 4(!BAD Don‟t MIX)
IndentationPHP(Drupal)       Wordpress(PHP)   C(K&R                                   standard)Use an indent of 2 Use real...
Indentation
Indentation Always MakeProper Indent.
Indentation   Use of Real Tabs, 4 space as Tabs, only    spaces is    controversial.   It‟s because same source code loa...
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 loa...
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 comme...
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...
Code consistency   Let a project has 3 members.   They watch this slide very carefully , and    realized the importance ...
Code consistency   Always use same standard throughout a    project.   All members of a project must choose a fixed    c...
Learn from Others   Don’t invent your own standard. All of the    issues have already been debated to death    by many ot...
How To Write Unmaintainable                             Code                                  Ensure a job for life ;-)  ...
References   http://wiki.mozilla.org/WebDev:FrontendCodeStandards   http://na.isobar.com/standards/   http://en.wikiboo...
Coding conventions
Coding conventions
Upcoming SlideShare
Loading in...5
×

Coding conventions

745

Published on

Coding Standard, Coding Best Practices

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
745
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
48
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Coding conventions"

  1. 1. CODE STANDARDS &BEST PRACTICESMd. Ibrahim Rashid [ irashid.com ]
  2. 2. Good Code Vs. Bad Code
  3. 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. 4. Ask Yourself? Is your code well organized and maintainable? Is you code well documented?
  5. 5. General Practices Naming Conventions Indentation Brace Style Commenting Code consistency Readability Vs. Compression
  6. 6. What should coding standardsprovide? File, class, variable naming conventions Code formatting conventions Guidelines for consistency across the code Uniformity
  7. 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. 8. Various ConventionsClass names MyClassMethod names my_function() myFunction() MyFunctionConstants MY_CONSTANTProperties and my_variable myVariablevariablesNon-public class _my_private_variable _myPrivateVariablmembers eFilenames MyFile.php myFile.php my_file.phpClass Filenames ClassMyFile.php classMyFile.php class_my_file.p hp Case insensitive : MyFile.php and myfile.php are same in windows
  9. 9. Example
  10. 10. Scenario 1
  11. 11. Scenario 2
  12. 12. Scenario 3
  13. 13. Senerio 4(!BAD Don‟t MIX)
  14. 14. IndentationPHP(Drupal) Wordpress(PHP) C(K&R standard)Use an indent of 2 Use real Tab = 4spaces, with no tabs and not spacestabs spaces,
  15. 15. Indentation
  16. 16. Indentation Always MakeProper Indent.
  17. 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. 18. Indentation Brace Style
  19. 19. Indentation Brace Style
  20. 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.
  21. 21. Indentation
  22. 22. Commenting Always try to put comments on your code.
  23. 23. Commenting
  24. 24. Commenting
  25. 25. Commenting
  26. 26. Self documenting code Use of Long Method Name that reflects the purpose of the method. Still It needs to be commented.
  27. 27. Code Readability Always try to make readable code.
  28. 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 inunreadable compact form.
  29. 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. 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. 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. 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. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×