Presentation is loading. Please wait.

Presentation is loading. Please wait.

Coding Conventions  Coding conventions are a set of guidelines for a specific software project that recommend programming style, practices and methods.

Similar presentations


Presentation on theme: "Coding Conventions  Coding conventions are a set of guidelines for a specific software project that recommend programming style, practices and methods."— Presentation transcript:

1 Coding Conventions  Coding conventions are a set of guidelines for a specific software project that recommend programming style, practices and methods.

2 File organization  Common well-structured folder hierarchy  Folder templates  Restrict user-creation folders to specific subfolders  Do not create overlapping categories  Many times file organization is dictated by the IDE or repository

3 Indentation  Examples of nesting rules:  Number of spaces indented after a function header  Number of spaces indented in a nesting  Increased readability is the goal

4 Comments  Types of comments  Descriptive blocks  Inline comments  Class comments (Descriptive block)  Method comments (Descriptive block)  Variable comments (Inline)  Comment while coding  Avoid obvious comments  Leave descriptive comments

5 Declarations  One or multiple declarations per line  Scope rules - modifiers

6 Statements  Forbidden statements (goto!)  Multiple criteria rules (use switch instead of nested ifs for >2 criteria)  Maximum levels of nesting  Preferred use (should use if then else instead of ternary operator)  Line length limits

7 White space  Line spacing  Spaces between keywords

8 Naming Conventions  Identifiers must be descriptive  Use underscore to separate words  Each word starts with a capital letter  camelCase: First letter of each word is capitalized, except the first word  Some developers prefer to use underscores for procedural functions, and class names, but use camelCase for class method names

9 Naming Conventions  Consistent temporary names  Capitalize SQL special words  SELECT id, username FROM user;

10 Grouping Conventions  More often than not, certain tasks require a few lines of code.  It is a good idea to keep these tasks within separate blocks of code, with some spaces between them.

11 Grouping Conventions  // get list of forums  $forums = array();  $r = mysql_query("SELECT id, name, description FROM forums");  while ($d = mysql_fetch_assoc($r)) {  $forums []= $d;  }   // load the templates  load_template('header');  load_template('forum_list',$forums);  load_template('footer');

12 Separate Code and Data  Rules should be enforced to separate code from data  This is the root cause of every buffer overrun/overflow exploit

13 Duplicate Code  DRY stands for Don't Repeat Yourself.  Also known as DIE: Duplication is Evil.  The principle states: "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."


Download ppt "Coding Conventions  Coding conventions are a set of guidelines for a specific software project that recommend programming style, practices and methods."

Similar presentations


Ads by Google