What is the difference between StudlyCaps and CamelCase?

后端 未结 4 1087
悲&欢浪女
悲&欢浪女 2021-02-01 15:59

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

相关标签:
4条回答
  • 2021-02-01 16:12

    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.

    0 讨论(0)
  • 2021-02-01 16:13

    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).

    Some people and organizations, notably Microsoft (and seems the authors of PSR-1 too), use the term camel case only for lower camel case. Pascal case means only upper camel case.

    0 讨论(0)
  • 2021-02-01 16:13

    i call it actually PascalCase when the identifier has two words each one begins with capital letters.. and i use it in C# for methods names, and camelCase for variablesNames, instanceFelds.. ClassNames also for PasaclCase..

    0 讨论(0)
  • 2021-02-01 16:32

    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.

    0 讨论(0)
提交回复
热议问题