Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

camel case method names

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?

like image 849
Jeremy Avatar asked Oct 22 '09 19:10

Jeremy


People also ask

Are method names CamelCase?

Methods should be verbs in lowerCamelCase or a multi-word name that begins with a verb in lowercase; that is, with the first letter lowercase and the first letters of subsequent words in uppercase. Local variables, instance variables, and class variables are also written in lowerCamelCase .

Which of these names are examples of CamelCase?

The name refers to the internal capital letters, which resemble the humps on a camel's back. For example, ComputerHope, FedEx, and WordPerfect are all examples of CamelCase.

What is the camel case variable name?

Camel case starts each new word in a complex variable name with an uppercase letter. You can capitalize the first word as well or leave it lowercase. When the first letter of the variable starts with an uppercase letter, it is known as upper camel case.

What is CamelCase example?

/ˈkæm. əl ˌkeɪs/ the use of a capital letter to begin the second word in a compound name or phrase, when it is not separated from the first word by a space: Examples of camel case include "iPod" and "GaGa".


2 Answers

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.

like image 104
Bill Avatar answered Sep 25 '22 18:09

Bill


It's just a convention. Like all conventions they only serve to, in the minds of their creators, make code easier to read and maintain.

like image 32
popester Avatar answered Sep 22 '22 18:09

popester