目錄
https://code.google.com/p/google-styleguide/ http://lxr.linux.no/linux/Documentation/CodingStyle http://perldoc.perl.org/perlstyle.html http://www.gnu.org/prep/standards/
使用 UNIX 風格換行, 請在你的編輯器內調整
UNIX (LF或"\n") MAC OS (CR 或"\r") Windows CRLF \r\n
源碼檔案使用 UTF-8
有些IDE環境 UTF-8 BOM
if, while, for, foreach, do ... loop, switch... 等的嵌套必須小於等於3層
如下面的例子,可讀性極差。
if (xxx){ if (xxx){ if(xxx){ if(xxx){ if(xxx){ } } } if(xxx){ if(xxx){ } } } if (xxx){ if(xxx){ if(xxx){ } } if(xxx){ if(xxx){ } } } }
加以改造
func aaa(p){ if(p){ if(xxx){ } } } func bbb(b){ if(b){ if(xxx){ if(xxx){ } } } } if(xxx){ aaa(xxx) } if(b){ bbb(b) }
<?php /** * Project Name * * @author $Author: netkiller $ * @copyright Copyright (c) 2012 Company * @version $Id: chapter.coding.xml 584 2013-05-15 05:13:17Z netkiller $ */ <?php /** * Project Name * * @author $Author: netkiller $ * @license GNU General Public License 2.0 * @version $Id: chapter.coding.xml 584 2013-05-15 05:13:17Z netkiller $ */