This repository has been archived on 2025-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
qemudb/CODING_STANDARD

116 lines
3.1 KiB
Plaintext
Raw Permalink Normal View History

WineHQ Application Database Coding Practice
2006-06-26 17:25:19 +00:00
/**
* 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
2006-06-26 17:25:19 +00:00
/**
* 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
2006-06-26 17:25:19 +00:00
/**
* 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)
2006-06-26 17:25:19 +00:00
/**
* general coding guidelines
*/
1) functions, loops and if's are written this way (look at the way {}'s are lined up):
2005-01-10 22:13:47 +00:00
<?php
2006-06-26 17:25:19 +00:00
function do_foo($sVar)
{
2006-06-26 17:25:19 +00:00
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
2006-06-26 17:25:19 +00:00
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.)
2006-06-26 17:25:19 +00:00
2006-06-26 17:25:19 +00:00
/**
* comments
*/
1) function, method, header and multiline comments:
/**
* This functions does nothing interesing.
* More comments to come here...
*/
function bar()
{
foo();
}
2006-06-26 17:25:19 +00:00
2) one-line comments
// This is a one line comment
2006-06-26 17:25:19 +00:00
3) always put a single space after the comment mark
2004-12-29 03:38:37 +00:00
2006-06-26 17:25:19 +00:00
4) never use # for commenting as it will become obsolete in the future
2007-11-23 22:18:36 +01:00
/**
* 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";