Coding Standards - Akif1080/Virtual-Shop-Management-System- GitHub Wiki

Php coding standard

Introduction:

• Coding standards are the set of guidelines defined for a specific language that recommend style, practices to be followed for each piece of code in a programming language. • Normally it includes guidelines for naming conventions for variables, formatting and indentations, comments, file naming etc.

Why coding standards?

• Your peer programmers have to understand the code you produce. A coding standard acts as the blueprint for all the team to decipher the code. • Simplicity and clarity achieved by consistent coding saves you from common mistakes.

Guidelines for coding standards:

Closing PHP Tag:

•Files containing only php code should always contain the closing PHP tag(?>).This prevents many of the elusive white screens of death.

Comments

For documentation comments we will use (//) format. Otherwise comment will be given by //

Indentation

we will use tabs for indentation. Example: if($arg==true) { ....//do something here } else($arg===null) { ....//do something else here }

Spacing

No spacing between operators, assigments ("=") and their operands. Example: $x = ($a+$b)*$c/$d+foo();

File Naming Conventions:

•All file names must be all lower case. No exceptions.

Class name:

•Class names should not have underscores to separate words, and each word in the class name should begin with a capital letter. For example: Class user-customer { }

Methods Name:

•Method should have underscores to separate words, and all letter will be a higher letter. For example: Class user-admin

Public function GET_DATA($name,$data) { //some code here } }

Variables name:

• Variable names should be concise and contain only lower-case letters and underscores between two word . • Loop iterators should short, preferably a single character. For example: $first_name $last_name For($i=0; $i<$max;$i++)