WineHQ Application Database Coding Practice

/**
 * HTML
 */
- Respect html coding standards. The current doctype is HTML 4.01 transitional (http://www.w3.org/TR/REC-html40/)
Try to make your content validate nicely (http://validator.w3.org/)

Avoid using implicitly closed elements eg. <br/> in HTML 4.01 transitional, as it can lead to validation errors.
http://www.w3.org/TR/html401/struct/text.html#edef-BR

/**
 * Variables naming
 */
variables that don't come from outside your script (i.e. that aren't fetched from superglobals) should be named this way 
(a.k.a hungarian notation):
prefix + var_name

Where prefix is one of:
Scalar types:
i for integers
f for floats
s for strings
sh for html strings
b for booleans
Compound types:
a for arrays
o for objects
Special type:
h for handles

the rest of the variable's name is using camel style
examples:
$aUsers
$iTopicId
$hRecordSet 
$sQuery
$hResult


/**
 * Functions naming
 */
1)functions name should be declarative and be prefixed with the name of the module (=file) where it is stored (for example image_show_thumbnail())
2)methods (functions inside a class) are named like this: setMyName() (i.e. words separated with an upper case character)
3)normal functions (outside a class) are named like this: query_appdb() (i.e. words separated with an underscore)


/**
 * general coding guidelines
 */
1) functions, loops and if's are written this way (look at the way {}'s are lined up):
<?php
function do_foo($sVar) 
{
    if(isset($sVar))
    {
        echo "bar";
    } else
    {
        echo "foo";
    }   
}
?>

2) indentation is made of 4 spaces (no tabs please)

3) line length should be no more than 130 characters, preferably < 80

4) use long php tags (<?php ?>) instead of short ones (<? ?>) as :
 a) it could be removed from future versions of php
 b) if conflicts with tags like <?xml version=1.0 ?> that are used in xhtml

5) do not use vars that require register_globals to be on as:
 a) it is off by default in php 4.1+
 b) it is more secure
 c) it makes it easier to understand where your vars are coming from (forms, session, etc.)


/**
 * comments
 */
1) function, method, header and multiline comments:
/**
 * This functions does nothing interesing.
 * More comments to come here...
 */
function bar()
{
    foo();
}

2) one-line comments
// This is a one line comment

3) always put a single space after the comment mark

4) never use # for commenting as it will become obsolete in the future

/**
 * string quotes
 */
There are two different ways to quote strings in PHP - single quotes or double quotes.
The difference is that the parser does variable interpolation in double-quoted strings, but not in single quoted strings.
Because of this, always use single quotes unless the string contains a variable that needs to be parsed.

Also if the string contains a variable put it inside double quotes instead of using 'bla' . $var . 'bla';
To increase readability of the code.
Wrong:
$str = "This is a long string without any variables";
$str = 'This string contains a variable ' . $var . ' enough said.';

Right:
$str = 'This is a long string without any variables';
$str = "This string contains a variable $var enough said";