gpt4 book ai didi

Bash 编码约定

转载 作者:行者123 更新时间:2023-11-29 08:49:08 25 4
gpt4 key购买 nike

我正在尝试学习一些 Bash,以便有一天能找到一份与计算机打交道的工作。

为了提高我的清晰度并训练我编写自学代码,我正在努力遵守一套一致的“指导原则”。

当我推出自己的“指南”时,我显然会问自己:我不应该改用既定标准吗?

我找不到 Bash 这样的“权威”引用,类似于这些其他语言的引用:

是否有指向 Bash 的类似文档的链接,该文档有充分的使用理由?

这是我自己整理的东西类型...但我认为,尤其是作为初学者,我应该使用专家编写的指南,而不是试图提出我自己的指南,因为他们不会基于丰富的经验、洞察力、实用性、常见模式/反模式的知识等。

您可能会质疑这些文档的有效性,但有些人肯定喜欢它们,因为网络上有我在上面的要点列表中提到的在线例子..


################################################################################    
# Coding conventions
#
# - Prefer lines of 80 characters of length or less
#
# - Perform arithmetic operations and numeric comparisons within "(( ))" blocks
# e.g. if ((42<=24+24)), ((3**3==27))
#
# - Reference variables by name, not expansion, within arithmetic evaluation
# e.g. ((i++)) rather than (($i++)), ((v+=42)) rathern than v=$(($v+42))
#
# - Prefer "[[" to "[" for conditional expressions
#
# - Prefer "[[ $s ]]" to "[[ -n $s ]]" when checking for empty strings
#
# - Document each function with at least a summary sentence. This should not
# exceed the preferred line length, be written in third person, end with a
# period and concisely describe the general utility of the function
#
# ...
# ...
# ...
#
################################################################################

最佳答案

我遇到的最好的 bash 风格指南 is from Google .

还有一些额外的建议from the Chromium project .

对于学习 bash,Apple Developer Shell Scripting primer非常好。

使用 bash 风格指南是相当明智的,因为它充满了技巧和意想不到且难以诊断的怪癖。因此,如果您一直遵循相同的风格,那么您应该只对每个技巧上当一次。

关于Bash 编码约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15610794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com