2004-12-11 03:42:43 +00:00
|
|
|
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/)
|
|
|
|
|
|
|
|
|
|
- Think about upward compatibility. Some day we might choose another doctype like XHTML 1.0
|
|
|
|
|
(i.e. <br /> instead of <br>, avoid using styles tag and properties (bgcolor, borders & Co) and use stylesheets instead)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#######
|
|
|
|
|
# PHP #
|
|
|
|
|
#######
|
|
|
|
|
- functions are written this way (that way {}'s are lined up):
|
|
|
|
|
<?
|
|
|
|
|
function foo()
|
|
|
|
|
{
|
|
|
|
|
if(isset($var))
|
|
|
|
|
{
|
|
|
|
|
echo "bar";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
- indentation is made of 4 spaces (no tabs please)
|
|
|
|
|
|
|
|
|
|
- line length should be no more than 130 characters, preferably < 80
|
|
|
|
|
|
|
|
|
|
- comments: Muli line code should look like this.
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This functions does nothing interesing.
|
|
|
|
|
* More comments to come here...
|
|
|
|
|
*/
|
|
|
|
|
function bar()
|
|
|
|
|
{
|
|
|
|
|
foo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If you want to highlight some thing this is permissable. for a single line
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if(!isset($appId))
|
|
|
|
|
{
|
|
|
|
|
/* a single comment should be like this */
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/* Shows a particular version. */
|
|
|
|
|
if($versionId)
|
|
|
|
|
{
|
|
|
|
|
/* Code comes here */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shows an apps summary */
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Another code comes here */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-11 19:40:01 +00:00
|
|
|
- use long php tags (<?php ?>) instead of short ones (<? ?>) as :
|
|
|
|
|
1) it could be removed from future versions of php
|
|
|
|
|
2) if conflicts with tags like <?xml version=1.0 ?> that are used in xhtml
|
2004-12-11 03:42:43 +00:00
|
|
|
|
2004-12-11 19:40:01 +00:00
|
|
|
- do not use vars that require register_globals to be on as:
|
|
|
|
|
1) it is off by default in php 4.1+
|
|
|
|
|
2) it is more secure
|
|
|
|
|
3) it makes it easier to understand where your vars are comming from (forms, session, etc.)
|
2004-12-29 03:38:37 +00:00
|
|
|
|
|
|
|
|
- variables naming
|
|
|
|
|
variables that don't come from outside your script (i.e. that arent fetched from superglobals) should be named this way
|
|
|
|
|
(a.k.a hungariant notation):
|
|
|
|
|
prefix + var_name
|
|
|
|
|
|
|
|
|
|
Where prefix is one of:
|
|
|
|
|
Scalar types:
|
|
|
|
|
i for integers
|
|
|
|
|
f for floats
|
|
|
|
|
s for 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
|