任何合作的项目都需要一致性和稳定性才能保持它的强壮。
编写这些准则的目的是为所有的Moodle代码提供一个努力的目标。有一些比较老的已经存在的代码在极少的方面尚未达标,但它们最终将会被修正。所有新的代码都必须尽可能地遵守这些准则。
如果需要上传一个帮助文件:
我知道,如果你已经习惯了一种编码风格而我却让你改变它是有一点讨厌的,但比较而言,这比日后所有人都需要去搞清混合风格的Moodle代码要好一些。对于人们使用的任何编码风格都有很多支持和反对的意见,但现在正在使用的风格已经存在了,因此请坚持下去。
好的: $quiz
好的: $errorstring
好的: $assignments (用于数组)
好的: $i (仅用于小型循环)
坏的: $Quiz
坏的: $aReallyLongVariableNameWithoutAGoodReason
坏的: $error_string
define("FORUM_MODE_FLATOLDEST", 1);
function forum_set_display_mode($mode=0)
{
global $USER,
$CFG;
if ($mode)
{
$USER->mode
= $mode;
} else if (empty($USER->mode))
{
$USER->mode
= $CFG->forum_displaymode;
}
}
if ($quiz->attempts)
{
if ($numattempts >
$quiz->attempts)
{
error($strtoomanyattempts,
"view.php?id=$cm->id");
}
}
$var = 'some text without any
variables';
$var = "with special characters like a new line n";
$var = 'a very, very long string with a '.$single.' variable in it';
$var = "some $text with $many variables $within it";
/**
* The description should be first, with asterisks laid out exactly
* like this example. If you want to refer to a another function,
* do it like this: {@link clean_param()}. Then, add descriptions
* for each parameter as follows.
*
* @param int $postid The PHP type is followed by the variable name
* @param array $scale The PHP type is followed by the variable name
* @param array $ratings The PHP type is followed by the variable name
* @return mixed
*/
function forum_get_ratings_mean($postid,
$scale, $ratings=NULL)
{
if (!$ratings)
{
$ratings
= array(); //
Initialize the empty array
if ($rates
= get_records("forum_ratings",
"post", $postid))
{
//
Process each rating in turn
foreach
($rates as $rate)
{
....etc
foreach ($objects
as $key =>
$thing) {
process($thing);
}
if ($x ==
$y)
{
$a
= $b;
} else if ($x ==
$z) {
$a
= $c;
} else {
$a
= $d;
}
Version: $Id$