What is the difference between StudlyCaps and CamelCase?

喜夏-厌秋 提交于 2019-12-03 09:19:24

问题


PSR suggests, method names MUST be declared in camelCase and class names MUST be declared in StudlyCaps.


回答1:


StudlyCaps, also known as PascalCase, implies that the first capital of each subword is capitalized. camelCase implies, like a camel, that the humps are in the middle, therefore the first letter is not capitalized.

Compare Microsoft's standards for .NET.

Other well known capitalization styles are snake_case, where all words are concatenated in lowercase with underscores, and kebab-case, which is identical but uses a hyphen.




回答2:


CamelCase is where the first letter of each sub-word in a name is capitalised. The first letter of the whole name can be upper or lower case, and is generally (always?) lower case in programming.

StudlyCaps is a little weird. There are capital letters, but they can be at any letter according to some rule, not just the beginning of a sub-word. The classic example is (was) HoTMaiL.

My understanding of the PSRs is that their intention is that each sub-word should be capitalised in both instances, with classes having an initial upper-case letter and methods an initial lower-case letter.




回答3:


In PSR-12 there is an explanation of what they meant by StudlyCaps:

The term ‘StudlyCaps’ in PSR-1 MUST be interpreted as PascalCase where the first letter of each word is capitalized including the very first letter.

source: https://www.php-fig.org/psr/psr-12/#21-basic-coding-standard

P.S.

For clarity, there are two alternatives for camel case - upper camel case (initial uppercase letter, also known as Pascal case) and lower camel case (initial lowercase letter, also known as Dromedary case).



来源:https://stackoverflow.com/questions/32731717/what-is-the-difference-between-studlycaps-and-camelcase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!