camel case method names

2019-02-12 18:23发布

I understand the reason to camel case variable names, but I've always wondered why you would camel case a method name? why is it toString() and not ToString()? What purpose does it serve?

12条回答
劳资没心,怎么记你
2楼-- · 2019-02-12 18:51

Pascal case The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. You can use Pascal case for identifiers of three of more characters. For example: BackColor

Uppercase All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or less letters, or abbreviations, such as BSU and UCS. In the example below, IO and UI are the uppercase identifiers, whereas System follows the Pascal capitalization style because the length is greater than two. For example: System.IO; System.Web.UI

Camel case The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. For example: backColor

The following Link summarizes the capitalization rules and provides examples for the different types of identifiers and items within your Web application/project.Hopefully this link will helpful for you

https://dotnetprod.bsu.edu/AdminConsole/Documentation/ASPDotNet/CodingStyle/NamingConventions/Capitalization.aspx

查看更多
再贱就再见
3楼-- · 2019-02-12 18:52

If you want a function

write();

that takes less effort (one less SHIFT keypress) than

Write();

However, if you're writing to a file, you need to distinguish the words. Hence

writeToFile();

is marginally more efficient (and still consistent with the first example)

查看更多
做自己的国王
4楼-- · 2019-02-12 18:54

A lot of conventions say you capitalize the first letter of types (classes, structs, enums, etc.), and use lowercase otherwise (functions, members, etc.).

If you follow that convention, you can then tell just by looking that MyStruct.MyType refers to a nested type, and MyStruct.myData refers to some form of data, and MyStruct.myFunc() refers to a function call.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-02-12 18:58

Because that's what the original designers of Java liked.

查看更多
贪生不怕死
6楼-- · 2019-02-12 19:00

I don't think there is any reason, these are just conventions and everyone might have his own.

查看更多
ゆ 、 Hurt°
7楼-- · 2019-02-12 19:05

We use lower-case on the first letter to save a little ink in our printouts.

查看更多
登录 后发表回答