I use a mix of underscores and camelBacks across all my code - that might sound odd, but there’s a method to my madness.
camelBacks I choose as my primary formatting method because it’s what javascript uses and suggests using, so I use it across all my code - HTML, CSS, PHP, PERL, etc - so I have one consistent naming convention. All my classes, ID’s and functions of the past… six years or so use camelBacks.
But I also use underscores in a handful of cases, often in COMBINATION with camelBacks. For example a section delimiter in a name - for example if I have two fieldsets with near identical information in the same form, the first one being “your info” and the second one being “spouses info” and both have a ‘name’ field, I’ll prefix the fieldset className before each.
your_name, spouses_name
I also often use underscores on classes or ID’s when using them as javascript hooks as it lets me divide up the element…
<span id=“sControl_myContent1”></span>
<div id=“myContent1”>Some text</div>
My javascript can then pulls all spans, checks for the sControl_ prefix (substr), attach the onclick handler, fill in some content, and use the end of the ID to target the DIV. Scripting off content is always shown and controls are not, scripting on the control gets added.
Another example would be a code library. If I have multiple library files I’ll use the prefix_ structure to say what library a function is from, while using camelBacks for the actual function name.
For example:
function common_camelBack($inString) {
return lcfirst(str_replace(
array(
' ',"\
","\ ","\\r",' '
),'',ucwords($inString)
));
}
function common_randomPassword($min=8,$max=12) {
I then know those functions are stored in /libraries/common.php, just as I would know:
function forms_isValidEmail($address) {
is in /libraries/forms.php
Also prevents namespace headaches.
Really though it just helps me make my code feel cleaner/clearer. Same reason I use XHTML and have burned out tab and enter keys on “Model M” Keyboards. (which if you know what those are, your head just exploded like you were in the same room with Micheal Ironsides)