Show Menu
Cheatography

Code Standards Cheat Sheet (DRAFT) by

Coding Standards in Web Engineering

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Common PHP

PHPDoc
Always show a return value
KISS
Less code is better
.cnf/.ini for sensitive data
never versioned (maybe templated)
if you copy paste something
find an easier way to do it (new function)
Only use double Quotes when using \n
use break tags in html
if: else: endif; / foreach: endfor­each;

PHP Function Principles

One idea per functi­on/­class
Encaps­ulation
public, private, protected
Useful Names for Classe­s/M­ethods
Abstract Classes are Chassis
no new Abstra­ctClass
Interfaces are Blueprints
no implem­ent­ation, method();
Type Hinting
function method­(Array my_array, Object my_object)
__cons­truct()
no PHPDoc, no return value
Guard Classes
jump out early ( if (false) {return false} )
Shorthand Conditions
$variable = condition ? true : false;
no nested methods
always a return value
except __cons­truct()
__dest­ruct()
close db

PHP Functions

function () {
extract and test (guard classes)
transform
process
return $value­||$­boolean
}

PHP Log Redirect

error_­rep­ort­ing­(E_ALL ^ E_NOTICE);
ini_se­t('­dis­pla­y_e­rrors', 1);
ini_se­t('­log­_er­rors', 1);
ini_se­t('­err­or_­log', 'log/p­hp_­err­ors.log');
ini_se­t('­htm­l_e­rrors', 1);

PHP Exceptions

TimeStamp as the new Exception Code
try {} around the whole code
throw () sends exception to nearest try {}
catch (Exception $e) {} handles the error
@throws Exception in the PHPDoc

PHP Databases

always use mysqli or PDO
mysqli­->r­eal­_es­cap­e_s­tring()
(int) type casting
prepared statements
throw exception on 'no stable connec­tion'

PHP MVC

Never echo()
if echo() only in View
   

Common JS

App = { init: function () {} }
Parame­tri­esi­erung

Common CSS

Reset CSS