英文:
Can kebab case have upper case letters as first letter?
问题
kabab case 命名约定有严格的定义吗?kebab case 中允许大写字母吗?以下名称是否符合 kebab case?
Article
Article-Body
英文:
Is there a strict definition for kabab case naming convention? Are uppercase letters allowed in kebab case? Does the following names follow kebab case?
Article
Article-Body
答案1
得分: 1
是的,你提供的两个示例都遵循短横线命名法,这种命名法只涉及标识符中单词之间的分隔方式。根据维基百科的说法,这种命名约定也被称为“lisp-case”、“COBOL-CASE”或“brochette-case”。
值得注意的是,几乎每种编程语言都支持“PascalCase”和“camelCase”,大多数支持“snake_case”,但只有少数几种支持“kebab-case”(因为它与减法语法冲突)。关于蛇形命名法和短横线命名法的另一个有趣观察是它们在表达可读性和标识符可读性之间进行了权衡。以下是三个示例:
myFirstVariable - mySecondVariable
my_first_variable - my_second_variable
(- my-first-variable my-second-variable)
在第一个示例中,操作符“-”更加显眼,因此我们可以直接看出这是一个减法操作。在最后两行中,存在更多的“噪音”,因为下划线字符和短横线看起来有点像操作符。在这种情况下,标识符更容易阅读,但表达式更难阅读。
英文:
Yes, both of your examples adhere to the kebab case convention which only concerns how words in an identifier are separated. According to Wikipedia this naming convention is also called lisp-case, COBOL-CASE or brochette-case.
https://en.wikipedia.org/wiki/Naming_convention_(programming)#Delimiter-separated_words
It's worth noting that basically every programming language support PascalCase and camelCase, most support snake_case but only a few support kebab-case (since it clashes with the syntax for subtraction). Another interesting observation about snake case and kebab case is that they trade expression readability for identifier readability. Here are three examples:
myFirstVariable - mySecondVariable
my_first_variable - my_second_variable
(- my-first-variable my-second-variable)
In the first example the operator "-" stands out more so we see directly that this is a subtraction. In there last two lines there is more "noise" since the underscore character and the dash look somewhat like an operator. In this case the identifiers are easier to read but the expression is harder to read.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论