当前位置: 首页>>技术问答>>正文


如果这是camelCase what-is-this?

湖心亭 技术问答 去评论

问题描述

doSomething这样的术语的命名约定是骆驼案例。

do-something的命名约定将被调用?

最佳解决方案

Delimiter-Separated也可以使用下划线(Delimiter_Separated)。

…A common recommendation is “Use meaningful identifiers.” A single word may not be as meaningful, or specific, as multiple words. Consequently, some naming conventions specify rules for the treatment of “compound” identifiers containing more than one word.

As most programming languages do not allow whitespace in identifiers, a method of delimiting each word is needed (to make it easier for subsequent readers to interpret which characters belong to which word).

Delimiter-separated words

One approach is to delimit separate words with a nonalphanumeric character. The two characters commonly used for this purpose are the hyphen (“-“) and the underscore (“_”); e.g., the two-word name "two words" would be represented as "two-words" or "two_words". The hyphen is used by nearly all programmers writing COBOL, Forth, and Lisp; it is also common for selector names in Cascading Style Sheets. Most other languages (e.g., languages in the C and Pascal families) reserve the hyphen for use as the subtraction infix operator, so it is not available for use in identifiers and underscores are therefore used instead…

次佳解决方案

我称lisp-case缺乏一个更好的术语,而且由于缺乏在其他语言家庭中的使用(如果有的话)。

第三种解决方案

这个案例约定没有真正的具体标准名称,并且对它应该被称为什么是不同意的。

Lisp已经使用这个约定了几十年,如this Wikipedia entry所述。因此,lisp-case的Keith Layne’s answer是合理的,尽管它是原始的压印。

根据this Wikipedia entry,也可以称为spinal-case或kebab-case(大写版本称为Train-Case)。所有这些形式也被认为是原始的组合。

因此,本例中没有一个类似于snake_case或camelCase的widely-accepted名称,它们是widely-accepted。

第四种方案

我喜欢”caravan case”,因为它看起来像一个在一个大篷车链接在一起的令牌。如果你喜欢,你甚至可以画一辆骆驼的大篷车。

第五种方案

通常用于URL或其他可读取的案例。

参考文献

注:本文内容整合自google/baidu/bing辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:gxnotes#qq.com(#替换为@)。

本文由《共享笔记》整理, 博文地址: https://gxnotes.com/article/176925.html,未经允许,请勿转载。
Go