最常见、行业首选的格式化方法是什么?
我似乎无法在 SO 上找到一个好的问题,或者一个好的谷歌搜索似乎可以回答我的问题。在格式化代码“块”及其括号时,行业或大众的偏好是什么?以下是我试图解释的一些示例...
if($foo)
{
return $bar;
}
else
{
return $stackOverflow;
}
VS
if($foo){
return $bar;
}else{
return $stackOverflow;
}
当然,与其他主要语言有相似之处,当然还有使用大括号的任何代码块。我已经全面看到了这两种方法的使用,第一种方法似乎更有意义,因为它允许人们快速上下查找以找到匹配的括号。
你有什么想法?
I couldn't seem to find a good question on SO, or a good Google search that seemed to answer my question. What is the industry or popular preference when it comes to formating code "chunks" and their brackets. Here are some examples for what I am trying to explain...
if($foo)
{
return $bar;
}
else
{
return $stackOverflow;
}
VS
if($foo){
return $bar;
}else{
return $stackOverflow;
}
Of course, with similarities in the other major languages, and of course with any code blocks that use curly brackets. I have seen across the board both methods used, and the first one seems to make more sense as it allows one to quickly look up and down to find the matching bracket.
What are your thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据您是否与喜欢标准化惯例的公司合作,您将有义务使用它。
否则,请使用您觉得舒服的东西并保持一致。
对 OP 评论的回应:
在了解特定公司的标准是什么之前适应标准可能不值得。根据您是否从一份工作跳到另一份工作,他们可能有一套完全不同的标准,您现在必须重新适应。
Depending on whether or not you are working with a company that prefers a standardized convention, you would be obliged to use that.
Otherwise, use what you feel comfortable using and be consistent.
Response to OP's comment:
Adapting to a standard before knowing what the specific companies standards's are might not be worth while. Depending if you hop from one job to another they may have a completely different set of standards that you would have to now re-adapt to.
我工作过的大多数公司都使用过,
因为我目前更喜欢用 C# 进行开发,它遵循这种风格,现在很自然。
我还注意到,这很大程度上取决于语言,C(++) 和 Perl 程序员更喜欢在同一行上使用 {},而 C#、Java 和 PHP 开发人员更喜欢在自己的行上使用 { 和 }。
Most companies i worked for used
As i currently prefer to develop in C# which follows this style it now comes naturally.
I've also noticed that it greatly depends on the language, C(++) and Perl programmers prefer {} on the same line, C#, Java and PHP developers prefer { and } on their own lines.
叹。没关系。坚持您工作地点的任何标准。如果没有标准,则在编写自己的代码时保持一致,并在修改其他代码时使用已有的内容。
Sigh. It doesn't matter. Stick with whatever the standard is where you work. If there is no standard, be consistent when writing your own code, and use whatever is already there when modifying others code.
我更喜欢第二个,因为我不认为大括号是一个声明。无论如何,只是我的想法。
I prefer the second one, because I don't consider curly bracket an statement. Anyway, just my thought.