Naming compound classes/ids

What convention do you use to name multi-worded classes and ids?

I use hyphens for classes and ids, and save the underscores for php variables, etc and camelcase for javascript variables, etc. Just a habit of mine to help me keep everything straight.

Unless you are contributing code to a project that has established conventions (eg. PEAR, phpBB etc.) or are working with a team, you can pretty much code anyway you like that works for you.

This is true not only for naming, but also for spaces vs. tabs. curly braces on the own lines or not, leaving comments or not, and a host of many other things that can be done in different ways.

Some languages do have some rules. eg. An id can not begin with a number, certain “special” characters are not allowed, reserved words can’t be used. etc. And you need to be careful to namespace or avoid over-riding an existing “core” class / function.

But you’ll find those out the hard way soon enough if you don’t read documentation.

IMHO it is much more important to use names that clearly mean something than it is to worry about camelCase vs under_scores vs hyphenated-words

Just use what works for you and do your best to be consistent and you’ll be fine.

See also Best Naming Convention?

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.