Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function names in C++: Capitalize or not? [closed]

What's the convention for naming functions in C++?

I come from the Java environment so I usually name something like:

myFunction(...) { } 

I've seen mixed code in C++,

myFunction(....) MyFunction(....) Myfunction(....) 

What's the correct way?

Also, is it the same for a class method as well as a non-class method?

like image 600
user69514 Avatar asked Nov 21 '09 18:11

user69514


People also ask

Should function names be capitalized in C?

All methods and functions should begin with a capital letter. The first letter of each word should also be capitalized. Special characters such as dashes and underscores are prohibited.

Are function names case sensitive in C?

In programming languagesSome programming languages are case-sensitive for their identifiers (C, C++, Java, C#, Verilog, Ruby, Python and Swift).

Should functions have a capital letter?

According to the book "Javascript: the good parts", you should only capitalise the first character of the name of a function when you need to construct the object by "new" keyword.

Should functions be lowercase?

Function names should be lowercase, with words separated by underscores as necessary to improve readability. Variable names follow the same convention as function names. mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.


1 Answers

Since C++11, you may want to use either snake_case or camelCase for function names.

This is because to make a class work as the range-expression in a range-based for-loop, you have to define functions called begin and end (case-sensitive) for that class.

Consequently, using e.g. PascalCase for function names means you have to break the naming consistency in your project if you ever need to make a class work with the range-based for.

like image 117
emlai Avatar answered Sep 28 '22 05:09

emlai