Jonghwan  Hyeon
Jonghwan Hyeon

Reputation: 423

Which variable name is proper?

I want to make a variable that is condiments that the customer wants.

I thought 'condimentCustomerWants' is okay

But I would never see variable name that contains relative pronouns in other's codes.

So I asked to my friends, and he recommended 'customerWantsCondiment', which is sentence.

Hmm.. which name is proper, good, and readable?

Upvotes: 2

Views: 897

Answers (4)

ATaylor
ATaylor

Reputation: 2598

HOW you name your variables is entirely up to you, however they should always reflect what the variable is actually supposed to do.

If it is: 'Does the customer want a condiment', you'd want: CustomerWantsCondiment (true/false value, probably a boolean)

If it is: 'Which condiment does the customer want?', you'd want: CondimentCustomerWants (for example an int value)

They sound similar, but both have different meanings. Whatever works best for you, really.

You may also want to adhere to a variable name convention, starting your variable name with a letter, that indicates the type of the variable. That way, you will know the type of a variable at a glance, without having to look for the actual definition. Please note, that the introducing letter(s) are always lower case.

For example: bool bCustomerWantsCondiment; int iCustomerWantsCondiment; char *sCustomerWantsCondiment; etc.

For more information regarding the hungarian notation, please look here for example: http://en.wikipedia.org/wiki/Hungarian_notation

Also, for readability, you should use the 'CamelCase' convention. That means, each time you begin a new word in the variable name, start it with a capital letter.

Upvotes: 1

evg
evg

Reputation: 1338

desiredCondiment preferredCondiment condimentForCustomer preferredCondimentForCustomer wantedCondiment

and so on...

Upvotes: 3

Hanky Panky
Hanky Panky

Reputation: 46900

Depends on everyone's coding style really. i would do

requestedCondiment

Upvotes: 3

Justin Niessner
Justin Niessner

Reputation: 245499

I'll throw desiredCondiments into the mix.

Upvotes: 6

Related Questions