• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What standard naming is best used for multiple word variables?

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Just real quick - which is best?

acmeWidgetBlue
AcmeWidgetBlue
acmewidgetblue
Acme_Widget_Blue

And why?
 
Last edited:
Depends on the programming language. A lot of it is personal preference too. Some programming languages have standardized that variables starting with a capital letter are special, constants, class-level variables, or something like that, so be aware of that. Smushingwordstogether doesn't work too well either.

So I'd say it's a debate between camelCase and using_underscores_between_words.
 
Oh, I see.

This is for html and php. Web stuff. Reason I ask is I want to pick a standard and stick with it. Right now it's kinda all over the place.

So camelCaseStyle? Is there any reason not to just have all first letters in caps? CamelCaseStyle? It just looks better to me, or am I inviting some kind of future confusion?
 
As mentioned by Ken, some people/companies have certain style rules. E.g., I use CapitalCamelCase for names of classes, public functions and static/class consts, while camelCase is for local/member variables and private functions.
There's no hard reason, just a convention that makes it a little easier to read code, I picked it up at work.
 
You're going to all types of conventions as everyone has their own methodology and naming conventions.

Just do what's easiest for you to read/work with.

If you're doing web, PHP tends to use camel_case or camelCase while PHP frameworks with autoloaders tend to use Camel_Case in their class names and camelCase in their variable names.
 
If you're working for an organization, it's whatever the organization uses.

If you're a one man band, it's whatever you will remember.

If you're a one man band and you're in java script, pick one scheme, use it for everything and don't get cute - none of this "circle = new Circle()". Give everything a unique name and don't expect capitalization to do anything but screw you over. I recommend either all lower case and no fancy _, or CAPS LOCK MODE, simply cause they're easy rules to remember.
 
I prefer to use underscores in names, because lumping text together to with capital letters can become confusing.

initial_data_set vs initialDataSet

Which is easier to read from a glance? Personal preference I guess, but I prefer using underscores.
 
Po-tay-toe, po-tah-toe. Use what you want as long as it's consistent.

I usually prefer FooBarBaz for function/class names, camelCase for member/local variables, ALLCAPS for constants and ALL_CAPS for preprocessor labels.
 
What I use:

CapitalCamelCase - Class names
camelCase - Function names
words_with_underscores - Variable names
ALLUPPERCASE - Constants
 
Hungarian Notation is a disaster. Anyone who's ever done Windows programming in C++ feels me:

lpszFirstName
nSize
m_lpszFoobar

And don't forget let's really make things unsightly when doing typedefs:

LPCTSTR
PDWORDLONG
ULONGLONG

Gah!
 
Hungarian Notation is a disaster. Anyone who's ever done Windows programming in C++ feels me:

lpszFirstName
nSize
m_lpszFoobar

And don't forget let's really make things unsightly when doing typedefs:

LPCTSTR
PDWORDLONG
ULONGLONG

Gah!

I don't see the problem :| I do hate dealing with wide strings and variants.
 
Useful til you need to change the type of a variable....
That's what "Replace All" in the editor is for 🙂

I do use m_ for member variables, p prefix for all pointers, and sometimes b for booleans, I find this useful, but the full-blown HN, yeah, it's a bit annoying and often redundant.
 
Hungarian Notation is a disaster. Anyone who's ever done Windows programming in C++ feels me:

lpszFirstName
nSize
m_lpszFoobar

And don't forget let's really make things unsightly when doing typedefs:

LPCTSTR
PDWORDLONG
ULONGLONG

Gah!

I was forced to use it in the early 90's like everyone else working in windows and C++. I feel like it was a well-intentioned effort to decorate variable names with type information, that was fortunately rendered obsolete by tool developments.
 
I was forced to use it in the early 90's like everyone else working in windows and C++. I feel like it was a well-intentioned effort to decorate variable names with type information, that was fortunately rendered obsolete by tool developments.

I just realized that if I ever do anymore windows programming again (in C++ anyway), I'm probably going to make use of 'auto' on every line.

LPCTSTR indeed.
 
I do things a bit different depending on language. I've been programming mostly in Java lately, so I might miss a few things for other languages.

In Java:

ClassName
methodName
variableName
CONSTANT_VALUE

In C:

privateFunction
Namespace_GlobalFunction
localVariable
Namespace_GlobalVariable
CONSTANT_VALUE

in C#:

propertyValue
AccessorValue
(everything else, same as Java)

In C++:

_privateVariable (I don't like the underscore convention, but its been used in the projects I've worked on)
PublicVariable
privateFunction
PublicFunction
 
Last edited:
I mainly work in c++

ClassName or FunctionParameter
classMethod()
localVariable
m_memberVariable
CONSTANT_OR_ENUM

Naming convention really doesn't matter as long as it is used consistently throughout a project. I really hate hardtoreadnames sans camel case or underscores.
 
Last edited:
Back
Top