
I'm talking about anywhere you need to write multiple words, but can't use spaces. For example: CSS classes and id's, programming language variables and function names, website usernames or passwords, etc.
You can vote in the poll in the sidebar. Feel free to share your reasoning in the comments. Results in a monthish.
as an ex programmer, I was always a camelcase guy.. but in the last six months or so citing readability as a my reason i’ve migrated to hyphens. Underscores are simply an irritation to type repeatedly and quickly while coding.
if (html || css) hypens;
else camelCase;
I was always told it was bad form to use uppercase with html and css, has this changed?
I can’t answer your question but I’m also onboard with your paradigm:
* html & css – hyphens
* everything else – camel
Indeed. for html/css it should be hyphens, for php functions & else, camelCase is the best choice.
Jep, that’s the way (ah ah) I like it too.
Same here.
And, if java lower camelCase, if C# upper CamelCase
same again from me!
Same here!
It is not bad form to use uppercase with css. XHTML does not allow a mixture of upper and lower case but class names are not “html” they are classes, and css.
Not that I disagree with your choice but there is nothing wrong with camelCase for css.
Yeah, agree’d I should have specified CSS in my comment there, naturally assumed :D
although, I do sometimes use hyphens in php, however I wouldn’t entertain using hyphens in java or c++..
I think thats purely been influenced by other coders on the web, take word press functions for instance.
Personally I was taught camelCase for programming applications.
mixing my hyphens and underscores there.. lol
underscores is what I meant for php
/agree
I agree. For HTML, CSS and XSLT etc. where it’s possible to use hyphens, I always use them. Otherwise, camelCase will be used.
Also you typed ‘hyphen’ as ‘hypen’ in the poll…
I’ve been told the mirrorside of what Rob says. Namely, that php doesn’t allow hyphens. So since I dislike underscores, I was left with using camelCase.
And in CSS/HTML I like to use hyphens due to the selectability (try it: test-test, test_test) and I don’t use camelCase in CSS/HTML due to hyphens being easier to read in a css-file (using “mostly single-line” style) I can easilty see a tree-like structure this way.
Tho in PHP functionnames I’m 100% underscores . .
I used to do camelCase everytime, everywhere, then i migrated from Mysql to Postgresql and, becose postgresql doesnt allow camelcase in tables/columns name (but just lower-case), i got stuck.
I like to use the same ‘formatting’ on every language, so that’s it: hypens where they are allowed, underscores just everywhere else (php, for example)!
Interesting – I can select the whole phrase with underscores, but not with hyphens. At least in the browser, in Safari, and I checked – also in text editors… that counts as a point towards underscores in my mind.
As for readability – I feel underscores are more readable as separate words.
Sadly, however, I am not terribly consistent with this and have my own “logic” (which might be fairly random at times). I need to change this bad habit… but I prefer allonewordlowercase for some situations, then underscores_between_words, then hyphenated-words-if-they-are-more connected, and sometimes a combination_of_underscores-and-hyphens, which is just silly, and occasionally, camelCase, but that is mostly for javascript and php. If I had to pick one for html/css, I would go for underscores for readability and selectability.
Underscores in css classes and id’s
CamelCase in php functions.
i second
I’m exactly the same, just seems right to me.
Always camelCase :)
i like camelCase.
html/css: #search_bar [underscore]
functions: def myFunction [camelCase]
classes : class MyAwesomeClass [CamelCase]
I dont use hyphens anywhere.
with dilse
I like hyphens. I tend navigate with the keyboard and use command arrow a lot for jumping from word to word.
Hyphens are the only of those options which allow jumping between the inner-words. If I misspell an inner-word, it allows for easy navigation for fixing the problem.
Hypens are for true coders because there’s no shift key involved. And everyone knows that true coders are the laziest people alive. Hyphens cut work by 50%!
camelCaseIsNice()
What’s “casels”?
Hyphens in CSS/HTML and Camel Case in everything else sounds good to me as well.
Used to be an underscore guy, but now there’s is no way I’d use anything other than hyphens. Cleanest option by far.
I don’t do much programming, however, and I understand camelCase is used often there.
Why does it matter?
It doesn’t. Whatever works best for an individual is, by default, the best method.
Doesn’t mean that people can’t put their heads together to see how other people do things, however.
html/css: #search_bar [underscore]
functions: def myFunction [camelCase]
classes : class MyAwesomeClass [CamelCase]
I dont use hyphens anywhere.
Python Coding Style says CamelCase for classes and camelCase for functions
imho, python coding style (pep8) actually says ‘_’ for functions.
That’s are great..!
camelCase FTW!
Saving your bandwidth, 1 byte at a time!
LOL. Yeah, Minimalism rulesz xD
css: dashes.
programming c#: camel case (and pascal case)
when I write ruby (not very often): underscore (but i don’t like it too much because I have to press an extra shift).
I use the different styles because of the “best practices” of each language.
camelCase FTW! No matter what I’m writing in.
Also, thanks for posting this, I’ve often wondered what other people use.
Did I miss where you say what you prefer?
camelCase is perfectly all-round. I use it in CSS classes and ID’s as well as in PHP and Javascript variables and functions.
Hi. In css use only hyphens, in php only use underscores, in use only java and javascript only camelStyle… :))))) – honestly!!! :)))
I’m a camelCase guy ;)
Hyphens in CSS and HTML attributes. Read somewhere that older browsers glitch if you use underscores.
In other programming, I use underscores for variables and function/method names. Looks cleaner, in some way. Camelcase is not very readable I think.
I used to strictly be an underscore guy, but I’m starting to switch to hyphens because I type them faster.
I tend to use camelCase more than anything. But sometimes I do use hyphens. I absolutely HATE underscores. They are really hard for me to type. lol. So I avoid those as much as possible.
I always prefer…
HTML & CSS: hyphens
PHP & JS: underscores
VB.Net & C#: CamelCase
This is how I program too.
Aye, the way I program as well.
I may be weird but all three.
CSS is the dash.
PHP varibles underscores
PHP functions and JS Camelcase
Same for me.
How about a keyboard with a special underscore button so you don’t have to use the shiftkey
Programming: CamelCase
CSS: dashes
I really hate underscores. They take way too long to type. I use dashes in CSS because I like to keep as much stuff as possible in lowercase in my HTML.
CamelCase! MuchEasierToTypeAndTheReadabilityIsn’tHardAtAll. IfAnythingItMightJustImproveYourReadability.
I didn’t vote in the poll since it depends.
Anything a search engine can read you’re better off using dashes. Otherwise just be consistent.
I typically use underscores when programming, but even then it depends on the language. I try to use whatever seems most common in the particular language.
Between hyphens and underscores, such as in URLs, I always use hyphens.
Programmatically, I’ve preferred hyphens as well, but several languages don’t support them in variable and function names, so lately I’ve been migrating to CamelCase.
I generally use hyphens, though I slip-up and use underscores once in awhile, as I tend to name PHP functions along the lines of the_function_name(). I’m really not a fan of camelCase. It seems less legible to me.
It depends on what I am doing. With CSS & HTML I use hyphens, with AS3 I use camel case and underscores (for variables and constants respectively). Since this is a CSS blog I imagine you only meant for CSS use so I voted hyphens :)
Which is more search engine friendly? I was always told that using hyphens is the optimal way of write multi-word file names or URLs. Edumacate me!!
Hyphens are best when it comes to URLs – but what you use in programming doesn’t affect SEO.
Hyphens are in fact search engine friendlier as google is able to split by them but not by underscores. Underscores count as characters and though glue two words to a single big word which is unlikely to be a SEO keyword. CamelCase words can never be split by search engines as there can be no formal rule how to split.
It is however very unlikely that CSS classes and IDs will be considered by search engines.
I have always been fond of using underscores.
When working with rather large amounts of code underscores make the ascenders more visible and therefore easier to read (we read words largely by the shape of the word, and not letter by letter).
Hyphens and, to a much larger degree camelCase, has the effect of making the words look more like one big word, making it more difficult to quickly locate what you are looking for:
1: $this_is_a_variable
2: $this-is-a-variable
3: $thisIsAVariable
The first line has much more air between the words.
Well, that is just me.
I agree with you, i use underscores all the time, i have used camelCase, but then i find it hard to manage the code when i debug.
I agree also,
Underscores keep the words cleaner and more seperated then camelCase. For readability its win_win!
I use it for everthing is code: html/css, php and javascript.
Chris, I think you should specify when, since some of us, including myself, would answer like so:
Programming: CamelCase
CSS: hyphens
I think I will go with hyphens for the poll though ;)
I use_underscores in my CSS and PHP.
I just don’t like the look of hyphens, and I heard that it was best to keep everything lowercase.
This isn’t really fair. I try to match the accepted idioms of the languages I program in.
For CSS I use either underscores or hyphens depending on my mood. :)
For PHP and JavaScript I normally use underscores for variables, camelCase for function names, and MixedCase for constructors or object literals.
For Ruby I use underscores for both variables and functions.
For friendly urls I always use hyphens, all lower case.
Perhaps you need to limit the scope of the Poll to one language… maybe CSS ?
Unless I’m trying to save bandwidth, I use hyphens. Or limit myself to one word. Otherwise, I use CamelCase.
CamelCase
I like using dashes for CSS class names, underscores for DOM IDs.
That’s a nice system, I guess it’s handy when you want to use an ID that’s similar or the same as an existing class name.
I do underscores…always have. No reason, I just always do it like that :D
#top-nav
function db_connect()
I generally use CamelCase for speed (and out of habit) but I’m thinking that I may try and use hyphens in CSS, mainly for when other people who don’t have a programming background are going to be working on the same files.
Would love to cast my vote, although I cannot do so on my iPhone . Have to when I get home I guess!
I use dashes, the reason: SEO friendly filenames.
I’ve read that search engines interpret underlines as ‘nothing’ thus “about_company_name.php” would be the read as “aboutcompanyname”, and that is only one word that wouldn’t mean anything to search engines.
On the other hand “about-company-name.php” would be understood as “About Company Name”, thus giving the page a relevant name related to the type of content that page would have.
With that being said, everything I do, when it comes to naming, I use dashes instead of underscores or camelCase styles.
That’s the reason I use dashes as well. I use dashes for image names too, like bg-li-a-header.gif…
yes cameCase for Programming
Hyphens for CSS Selectors
and underlines sometimes for files (esp. for PC Windows-Systems which I sometimes don’t trust?)
My favorites are dashes and camelCase but the best would be just a plain ________Space.
Variations on CamelCase, everywhere except constants, those are in CAPITAL_UNDERSCORE.
I have strict coding standards for PHP and JS and apply them to html/css as well.
Besides, using hyphens makes the code unreadable to me (allthough I understand some disagree with that) and underscores are a bore to use on the keyboard.
I use underscores for id’s and camelCase for almost everything else
Personally I use them all.
In my code I never (I mean ever) use hyphens. The only place I use them is in files that do not contain code. ie: images.
For files that contain code I use underscores for the name.
In the code itself, I use camelCase for class names and underscores for the functions and methods. Also, I preceed all the names of private variables and methods with an underscore, even with php5 syntax.
So for instance that would look like a private method in a class in my code:
class MyClass
{
private _some_var;
private function _my_function()
{
// some code
}
}
camelCaseIsNotBadAtAll
Since I come from a Flash / ActionScript background, it was natural for me to go straight to camelCase. However, a couple of casing hiccups in some web languages lead to me using underscores out of prudence.
Does anybody know if it really makes a difference to use uppercase?
for DB Tables underscore, but programing wise I am onboard with the consensus here.
I’m a CamelCase guy, but am inconsistent and sometimes just combine the words with no Camel, but never use underscore or dash.
For CSS and HTML I used underscores, but some time ago, I switched to dashes.
PHP – camelCase
That was a difficult poll to answer because it really depends on what we’re referring to here. I’m pretty much with everyone else on the comments here in that:
html / css / domain names : hyphens
js / php / perl / ruby / etc: camelCase
usernames and stuff like that I tend to go underscores if there is going to be a space…which I always try not to have.
HTML/CSS: Hyphens.
URLS: Hyphens.
PHP/JS: camelCase.
It’s always best to use hyphens whenever possible for readability, seo, and it just looks sexy to tell you the truth.
PHP/JS is best using camelCase considering underscores are just plain annoying. I like using underscores with variables though, otherwise functions and such are definite camelCase.
HTML/CSS: Hyphens
Everything else: camelCase
looks like you need another option on your poll ;)
camelCase to replace spaces between words, underscores to indicate important distinctions. eg: sampleFile_v01
I also dislike typing underscores. So I prefer hypens and camelCase.
Used to be an underscore type of person, but recently (like tonight after reading the comments), for CSS and HTML ONLY, I use hyphens for select ability, for everything else (PHP, Obj-C, JS, etc.) It’s camelCase all the way!
Most time: underscore, because they are easy to read
camelCase for almost anything.
Underscores out of habit, but it’s a habit I’m trying to break. Hyphens accomplish the same thing, but without getting the shift key involved, so why don’t I use them? No clue.
ILoveCamelCase…
Since I do a lot of programming in Rails, I have to use all three of those — camel case for classes, underscores for function names and hyphens in CSS. But if I prefer hyphens, because I can avoid the shift key there.
Hyphens are nice. Hate underscore. Sometimes CamelCase.
I like camelCase, and always use it for almost programming language.
Anyway just curious, what about your filename like
- filename.php
- fileName.php
- file_name.php
Coming from an XML/XHTML side of things, I’ve never used camelcase because of the all lowercase standards.
And since PHP has had trouble with hyphens (or so i’ve heard) I’ve always defaulted to underscores for everything.
The web motion and CSS 3 advents makes me feel that a near day we’ll have CSS expressions using hyphens. I know JavaScript libs were hyphen is already a selector, and who don’t know “-moz-opacity”…
Underscore it’s not easy to type, but it’s a convention in many programming languages, were camel would not be very semantic.
I use all camelCase, saving 1 byte, compact code and anything that saves connection time. If i build a common css widget… i name as package clock_nav (for a clock widget).
I’ve done lots of research on JavaScript and CSS to build my lib (leaf.googlecode.com). The main point is what will come next about CSS expressions.
Sorry about my English and laarge comment. I felt that I should say it.
iLoveCamelCase… :)
Depends on what I’m doing.
- PHP / Java / CSS – Camelcase
- URL’s of websites – Underscores
- C# – PascalCase
- Almost never use Hyphens (unless I have to, like with CSS properties “margin-left”)
actually i do prefer milk with my coffee.
Interesting discussion going on… I love using camelcase always…
-Deepu
follow CSS build-in style use Hypens.
I don’t care too much as long as it’s consistent throughout the code. For example, Drupal and WordPress use underscores in all function names; Symfony and CakePHP mostly camelcase.
I agree with other people in terms of it depending on the language; html/css dashes are fine – in php they are not allowed.
In xhtml/css I use hyphens, in php or python I use CamelCase it is more readable to me
Agreed.
Seems to be one option missing. Lowercase only.
Yea and another two is missing.
tHiSiSaVaRiAbLe and THISISAVARIABLE
Those 2 and lowercase only are just not an option, because they are hArD tO rEad (aren’t they?)
Why the heck would you use lowercase only?
are* missing.
I used underscores since i started coding, but tried camelcase few months ago and it seems it’s the best.
camelCase, and underscores rarely
camelCaseFtw =3
btw, I Forgot to mention that… to make my camelCase really work for me, is better to use smaller words. =)
Mostly CameCase (I don’t want speacial chars in my variable or function names names)