+ 124
How do you name your variable?
Which naming convention do you prefer most? 1. UPPERCASE 2. lowercase 3. camelCase 4. under_score 5. SentenceCase 6. mIxeDcAsE
336 Respostas
+ 275
SentenceCase for classes,
camelCase for variables,
UPPERCASE for constants,
lowercase for packages.
+ 58
camelCase if I need to declare alot of variables, lowercase if it is just a small code and mIxeDcAsE if I just woke up early in the morning :F
+ 37
@Dayve You rebel! š
+ 32
What if we mix up every convention?
mIxeDcAsE....as stated above!šÆšÆ
+ 26
As per Google C++ Style Guide
(with a few edits here and there)
Naming
The most important consistency rules are those that govern naming.Ā
Type Names
Type names start with a capital letter and have a capital letter for each new word, with no underscores.
class UrlTableTester { ... struct
Variable Names
The names of variables (including function parameters) and data members are all lowercase, with underscores between words. Data members of classes (but not structs) additionally have trailing underscores.
a_local_variable
a_struct_data_member
a_class_data_member_
Common Variable names
string table_name; // OK - uses underscore.
string tablename; // OK - all lowercase.
string tableName; // Bad - mixed case.
Constant Names
Variables declared constexpr or const, and whose value is fixed for the duration of the program, are named with a leading "k" followed by mixed case.
const int kDaysInAWeek = 7;
Function Names
Regular functions have mixed case; accessors and mutators may be named like variables.
Ordinarily, functions should start with a capital letter and have a capital letter for each new word (a.k.a. "Camel Case" or "Pascal case"). Such names should not have underscores. Prefer to capitalize acronyms as single words (i.e.Ā StartRpc(), notĀ StartRPC()).
AddTableEntry()
DeleteUrl()
OpenFileOrDie()
Learn more: https://google.github.io/styleguide/cppguide.html#General_Naming_Rules
+ 23
lowercase="the simplest"
+ 22
I use semantic classnames of camelCase convention
+ 21
I prefer
3. camelCase
and
4. under_score
+ 19
I use all except lowercase and SentenceCase.
+ 19
I name the variables like this - camel_Case which involves everything one uppercase, lowercases, and an underscore
But it's up to the programmer how he names the vars according to his convenience
+ 18
1 Letter at a time
+ 18
It's always better to follow the standards
UPPERCASE --> CONSTANTS
lowercase --> packages or libraries
camelCase --> functions or methods
SentenceCase --> Classes
under_score --> variables or pointers (very rare)
miXeDcaSe --> I never tried this š
+ 17
Thx to every single one of you for liking my answer. You gave the 'popular answer' badge to me š
Special thx to Tamra who was the hundredth upvoter!
+ 15
lowercase and UPPERCASE
+ 15
I usually name variables in lowercase until I name it using two words. When I use two words as variable's name, I use camelCase as it is easy to read for everyone. If you want to write variable name in lower case using two words, use an underscore sign (_).
+ 14
sentenceCase.
+ 14
camelCase is easier to write and read.
+ 14
camelCase and lowercase
+ 13
I usually use SentenceCase
+ 13
simply its better, I think, to name your variable in lower case and constants in upper. it will create a simple distinction and will be easy to maintain the code.