站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
Gallery:编码标准
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
==缩进== 缩进的基本单元是4个空格。达到此目的的最有效方法就是使用8空格制表宽度和空格的混合,如下所示: function myFunction() { /* 4个空格 */ code; code; if (indentAnotherLevel) { /* 8个空格,或1制表宽度 */ moreCode; moreCode; if (indentAnotherLevel) { /* 12个空格,或1制表宽度加4个空格 */ moreCode; moreCode; } } } 某些人喜偏好编辑器定义1制表宽度为4空格。但在编辑Gallery代码时不要这么做!因为其他人要查看此文件的话就要重新定义制表字符或代码才能符合你的方式,这并不好。举个例子,其他如sourceforge.net SVN的浏览器,会将制表宽度理解为标准的8空格为单位,那么你所有的代码就会显得不一样了。所以请遵守标准的8空格的制表宽度。 某些如Emacs和VI的编辑器会自动为你创建这种混合的tab和空格(Emacs中这被称为"smart tabs"模式)。这比单纯使用空格要有效率的多,因为这能降低文件中的字节数(由于多行代码会具有一个或多个缩进级别)。如果出于某种原因,你的编辑器不支持smart tabs而你又觉着太麻烦,可以使用[[Image:Repair-indention.zip|这个脚本]]进行文件的更新。 ===行长=== 避免每行超过100个字符。对,你没看错,是'''100'''而不是80。因为现在的电脑屏幕更“宽”更“大”了。 ===包装行=== *Break after a comma. *Break before an operator. *Prefer higher-level breaks to lower-level breaks. *Align the new line with the beginning of the expression at the same level on the previous line. *If the above rules lead to confusing code or to code that's squished up against the right margin, just indent 8 columns instead (not 4 columns). Here are some examples of breaking method calls: someMethod(longExpression1, longExpression2, longExpression3, longExpression4, longExpression5); var = someMethod1(longExpression1, someMethod2(longExpression2, longExpression3)); Following are two examples of breaking an arithmetic expression. The first is preferred, since the break occurs outside the parenthesized expression, which is at a higher level. /* '''PREFER''' */ longName1 = longName2 * (longName3 + longName4 - longName5) + 4 * longname6; /* '''AVOID''' */ longName1 = longName2 * (longName3 + longName4 - longName5) + 4 * longname6; Following are two examples of indenting function declarations. The first is the conventional case where the arguments are indented under the open parenthesis. In the second case, the function name is so long that indenting under the parenthesis would require us to put many parameters on their own line which is not visually appealing. But we can't indent the follow on lines by 4 columns because then it would be hard to differentiate them from the code that follows, so we indent them 8 columns, as we do when indenting wrapping if-clauses (see below). /* '''CONVENTIONAL INDENTATION''' */ function someFunction($anArg, $anotherArg, $yetAnotherArg, $andStillAnother) { codeHere; } /* '''INDENT 8 COLUMNS TO AVOID VERY DEEP INDENTS''' */ function superExtraHorkingLongMethodName($anArg, $anArg, $anArg, $anotherArg, $yetAnotherArg, $yetMoreArg, $anArg, $anArg $andStillAnother) { codeHere; } Line wrapping for if statements should generally use the 8 column rule, since conventional 4 column indentation makes it difficult to differentiate the predicate of the if-clause from its condition. For example: /* '''DON'T USE THIS INDENTATION''' */ if ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { /* BAD WRAPS */ doSomethingAboutIt(); /* MAKE THIS LINE EASY TO MISS */ } /* '''USE THIS INDENTATION INSTEAD''' */ if ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { doSomethingAboutIt(); } /* '''OR USE THIS''' */ if ((condition1 && condition2) || (condition3 && condition4) ||!(condition5 && condition6)) { doSomethingAboutIt(); } Expressions using the ternary operator should be parenthesized. Here are three acceptable ways to format ternary expressions: $alpha = (aLongBooleanExpression) ? $beta : $gamma; $alpha = (aLongBooleanExpression) ? $beta : $gamma; $alpha = (aLongBooleanExpression) ? $beta : $gamma; ===行终结=== Ensure that your editor is saving files in the Unix format. This means lines are terminated with a newline, not with a CR/LF combo as they are on Win32, or whatever the Mac uses. Any decent Win32 editor should be able to do this, but it might not always be the default. Know your editor.
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)