编码标准和线路长度 [英] Coding standards and line length

查看:115
本文介绍了编码标准和线路长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过的每个编码标准都有一行中的字符数推荐或绝对限制。在这个限制内有各种工作方式,但我没有看到这方面的任何具体指导。

Every coding standard I've ever seen has a recommended or absolute limit on number of characters in a line. There are various ways of working within this limitation, but I've not seen any specific guidance in this regard.

显然,如果可能,不要写过长的行。

Obviously, if possible, don't write excessively long lines.

但是如果这不现实呢?如何处理长线?

But what if that's not practical? How should long lines be handled?

这里有几个例子

if ($Stmt = $Mysqli->prepare("SELECT color, pattern, size,
                              manufacturer, mfgSku, storeLocation,
                              aisle, status
                              FROM tblItems WHERE ourSku = ?")) {

$flavors = array ('chocolate', 'strawberry', 'vanilla', 'cookie dough', 
                  'chocolate chip', 'mint chocolate chip', 'rocky road',
                  'peach', 'fudge brownie', 'coffee', 'mocha chip');

$Stmt->bind_result( $this->_firstName,
                    $this->_lastName,
                    $this->_BillToAddress->address1,
                    $this->_BillToAddress->address2,
                    $this->_BillToAddress->city,
                    $this->_BillToAddress->state,
                    $this->_BillToAddress->zip,
                    $this->_BillToAddress->country,
                    $this->_email,
                    $this->_status,
                    $this->_primaryPhone,
                    $this->_mobilePhone );

在每个例子中,长度代码的缩进是不同的。有没有更好的或更标准的方式这样做?如果额外的行总是以相同的方式缩进。

In each of these examples, the indenting of lengthy code is different. Is there a better or more "standard" way of doing this? Should extra lines always be indented the same way. Or is this OK?

推荐答案

在每个例子中都有一个模式 - 它们缩进到第一个参数功能。这是一个很好的标准,因为它将数据从水平转换为垂直,列允许阅读。

There is a pattern you can see in each example - they are indented to the first parameter of the function. This is a good standard to follow as it transposes the data from horizontal to vertical and the columns allow easy reading.

对于其他行长问题,如冗长的计算,首选方法是将其分解。计算朱利安日期或复活节是在几个步骤而不是一个长计算完成。

For other line length issues, such as lengthy computations, the preferred method is to break it down. Calculating the julian date, or easter is done in several steps instead of one long calculation.

- 亚当

这篇关于编码标准和线路长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆