Cheatography
https://cheatography.com
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: endforeach; |
PHP Function Principles
One idea per function/class |
Encapsulation |
public, private, protected |
Useful Names for Classes/Methods |
Abstract Classes are Chassis |
no new AbstractClass |
Interfaces are Blueprints |
no implementation, method(); |
Type Hinting |
function method(Array my_array, Object my_object) |
__construct() |
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 __construct() |
__destruct() |
close db |
PHP Functions
function () { |
extract and test (guard classes) |
transform |
process |
return $value||$boolean |
} |
PHP Log Redirect
error_reporting(E_ALL ^ E_NOTICE); |
ini_set('display_errors', 1); |
ini_set('log_errors', 1); |
ini_set('error_log', 'log/php_errors.log'); |
ini_set('html_errors', 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->real_escape_string() |
(int) type casting |
prepared statements |
throw exception on 'no stable connection' |
PHP MVC
Never echo() |
if echo() only in View |
|
|
|
|
Common JS
App = { init: function () {} } |
Parametriesierung |
|