...
// program code
}
$repssn_ind
=
$ssn_data
['index]->repssn_index;
$repssn_ni
=
$ssn_data
[index]->ni;
4.3. 较长的语句要分成多行书写
一行程序需小于
80 字符
较长的语句要分成多行书写,长表达式要在低优先级操作符处划分新行,操作符放在新行
之首,划分出的新行要进行适当的缩进,使排版整齐,语句可读。
循环、判断等语句中若有较长的表达式或语句,则要进行适应的划分,长表达式要在低优先
级操作符处划分新行,操作符放在新行之首示例:
代码如下
:
$perm_count_msg
->len = NO7_TO_STAT_PERM_COUNT_LEN
+ STAT_SIZE_PER_FRAM *
strlen
(
$len
);
$act_task_table
[
$frame_id
* STAT_TASK_CHECK_NUMBER +
$index
]->occupied
=
$stat_poi
[index]->occupied;
$act_task_table
[taskno]->duration_true_or_false
= sys_get_sccp_statistic_state(
$stat_item
);
if
((
$taskno
<
$max_act_task_number
)
&& (n7stat_stat_item_valid (
$stat_item
))){
...
// program code
}
for
(
$i
= 0,
$j
= 0; (
$i
<
$bufferKeyword
['word_index']->word_length)
&& (
$j
< new_keyword->word_length);
$i
++,
$j
++){
...
// program code
}
4.4. 一行只写一条语句
不允许把多个短语句写在一行中,即一行只写一条语句。示例:如下例子不符合规范
$rect
->length = 0;
$rect
->width = 0;
应如下书写
:
$rect
->length = 0;
$rect
->width = 0;4.5. 始终包含大括号
这是因为懒于多敲两个字符而给代码清晰带来问题的又一个情形。
示例:如下例子不符合规范
代码如下
:
if
(
$condition
) do_stuff();
if
(
$condition
)
do_stuff();
while
(
$condition
)
do_stuff();
for
(
$i
= 0;
$i
<
$size
;
$i
++)
do_stuff(
$i
);