我的一些同事遵循这种缩进风格,他们=
在赋值语句中的每个运算符之前和之后添加空格/制表符。即使块中只有一个赋值语句,他们甚至会这样做。我全力以赴编写可读、漂亮的代码。但是,真的需要在整个文件中进行这种对齐吗?
下面给出了演示这种缩进的示例代码。
public function getCMSSectionData($args="1")
{
$sql = "SELECT * FROM med_cms_section WHERE $args";
$data = $this->getdbcontents_sql($sql);
return $data;
}
public function insertCMSSection($dataArray)
{
$sendCount = 100;
$sql = "select * from med_email_pending order by priority desc limit ".$sendCount;
$res = $this->db_query($sql);
while($row = mysql_fetch_array($res))
{
$id = $row["id"];
$to = $row["to"];
$from = $row["from"];
$subject = $row["subject"];
$message = $row["message"];
$priority = $row["priority"];
$this->sendmail($to,$from,$subject,$message);
$this->sendmail("user@example.com",$from,$subject,$message);
$sql = "delete from med_email_pending where id=".$id;
$this->db_query($sql);
}
}
这不是:-
$sql = "SELECT * FROM med_cms_section WHERE $args";
$data = $this->getdbcontents_sql($sql);
比这更好:-
$sql = "SELECT * FROM med_cms_section WHERE $args";
$data = $this->getdbcontents_sql($sql);