Re:CamelCase vs. underscores: Scientific showdown
by libria on Tuesday March 03, 2015 @11:54AM
(#9138740)
I'm heavily biased in favor of the idiomatic style of the language I happen to be using. There's less context switching when interfacing with external libraries that are expected to follow the same.
There isn't a significant loss in velocity in adapting to use one or the other or even simultaneously (front_end_javascript, BackEndJava, SELECT * FROM blah). The most significant portion of my time is spent thinking/designing/debugging; I save the balls-to-wall frantic keyboard banging for NCIS cameos.
Re:CamelCase vs. underscores: Scientific showdown
by smhenderson on Tuesday March 03, 2015 @11:36AM
(#9138585)
Try choosing independently of (language) convention, habit or type of the identifiers.
That's the non-starter for me right there. I use whatever convention makes sense in the context of what I'm doing. Language, library and previous code in an existing project all dictate my choice in this matter.
Re:CamelCase vs. underscores: Scientific showdown
by danso on Tuesday March 03, 2015 @11:24AM
(#9138508)
From the OP's list of "Pro CamelCase":
> Camel case is easier to type, and underscores are hard to type.
I'll grant it that, but in the context of programming, this does not seem to be a "pro". After all, don't we spend far more time reading code than we do writing code?
I'm old, but I'm still surprised at how I have to fight over my reluctance to do something in another language (such as Python) when I remember that it's conventionally camelCase...on the other hand, I try to use it as a personal advantage...I can immediately tell in a body of code what helper functions originated from me, as I'll habitually write them in underscore (though this probably annoys the shit out of anyone who then tries to read/use my code).
Conversely, my enthusiasm for using R jumped when I read Hadley Wickham's style guide and saw that he endorsed underscores (http://r-pkgs.had.co.nz/style.html)
Re:CamelCase vs. underscores: Scientific showdown
by illcollins on Tuesday March 03, 2015 @11:38AM
(#9138599)
Agreed, although python convention is for underscores also.
According to pep8 "Function names should be lowercase, with words separated by underscores as necessary to improve readability. mixedCase is allowed only in contexts where that's already the prevailing style"
Re:CamelCase vs. underscores: Scientific showdown
by ttmarek on Tuesday March 03, 2015 @11:55AM
(#9138757)
PEP8 also says "The naming conventions of Python's library are a bit of a mess, so we'll never get this completely consistent -- nevertheless, here are the currently recommended naming standards. New modules and packages (including third party frameworks) should be written to these standards, but where an existing library has a different style, internal consistency is preferred."
Re:CamelCase vs. underscores: Scientific showdown
by Someone1234 on Tuesday March 03, 2015 @11:36AM
(#9138578)
I really like underscores for two word variable names. It only becomes a problem when you have variable names which are overly long, and your eyes have to move further.
But I don't really care that much. I'll just do whatever everyone else is doing. At least camcelCase keeps me from reaching for the _ as much and allows me to stay on the A-Za-z more of the time...
Re:CamelCase vs. underscores: Scientific showdown
by kbenson on Tuesday March 03, 2015 @11:50AM
(#9138705)
In my preferred language, CamelCase is often used to class names, and underscores for function/method names (as mentioned as in the article). Then again, my preferred language uses sigils so I don't need to rely on convention to differentiate things as much as some other languages.
Re:CamelCase vs. underscores: Scientific showdown
by lutusp on Tuesday March 03, 2015 @11:57AM
(#9138766)
Not mentioned in the article is the fact that an underscored file can be algorithmically converted to camel case, but not the reverse (with any reliability). Therefore camel case has higher entropy, lower information content, and is less flexible.
Also, the expression "scientific showdown" about studies that rely on psychological self-reporting is a bit of a stretch.
Re:CamelCase vs. underscores: Scientific showdown
by teamhappy on Tuesday March 03, 2015 @12:10PM
(#9138868)
Underscores win. Having said that; if your standard lib chose camels, that's probably what you should be choosing too. Consistency is the most important criteria.
I personally favour the C-style fuck-it-all naming scheme:
else if (like) {
likelowbar = true;
vote(lowbarfmt);
}
The narrower the columns, the easier it is for me to comprehend the algorithm. It also makes for great method names. Say "isatty" three times; it's fun, isn't it?
// BTW: I don't believe anyone telling me they can read camels more efficiently. Underscores add contrast, which aids your vision quite a bit.
Re:CamelCase vs. underscores: Scientific showdown
by teamhappy on Tuesday March 03, 2015 @12:43PM
(#9139160)
There is an objective, scientific truth to which one is easier to read. It_might_be_this_one, or ItMightBeThatOne. I don't know which one it is, but I do know that facts don't require opinion.
I'm glad you used the word "preference." I wish people wouldn't feel the need to justify arbitrary choices they make in life. It's your code and I will honour the choices you made if I ever end up working on it. You can't expect me to drink the Kool-Aid though.
Re:CamelCase vs. underscores: Scientific showdown
by louthy on Tuesday March 03, 2015 @01:03PM
(#9139320)
> ItMightBeThatOne
Are we discussing Pascal casing now? ;)
> There is an objective, scientific truth to which one is easier to read
I seriously doubt that. I would have thought that training over many years creates a bias one way or the other. I find It_might_be_this_one much harder to read than itMightBeThatOne. I much prefer kebab-casing-over-underscores also.
Perhaps there's a definitive answer for new programmers who have never seen either casing style? But for you to claim that those who disagree with you are drinking Kool-Aid is disingenuous.
Re:CamelCase vs. underscores: Scientific showdown
by teamhappy on Tuesday March 03, 2015 @01:39PM
(#9139632)
It is training over many years. The text you read most of the time isn't code though, which is exactly why I suspect the underscores to be more intuitive for your eyes. Please don't misunderstand the Kool-Aid part. I prefer "thisone" over all the others. It's probably the worst choice, but it works for me. I don't expect you to drink my Kool-Aid.
Re:CamelCase vs. underscores: Scientific showdown
by swhipple on Tuesday March 03, 2015 @11:40AM
(#9138612)
One point not mentioned in the article is that screen readers and other assistive technologies often produce better results when parsing words separated by underscores, so the code may be more accessible if it consistently uses an underscore-based style.
Re:CamelCase vs. underscores: Scientific showdown
by untog on Tuesday March 03, 2015 @11:32AM
(#9138551)
As of right now the results are as follows:
- CamelCase 52.34% (4,493 votes)
- underscores 47.66% (4,092 votes)
Which kind of says it all. Use whatever style you want, stop worrying so much about what other people are doing. Variable names a far more important than the formatting you use with them.
Re:CamelCase vs. underscores: Scientific showdown
by nkozyra on Tuesday March 03, 2015 @11:43AM
(#9138637)
I think "use whatever style you want" is a fair ethos for personal projects but the truth is it never works for teams.
If organizations allowed that you'd have no conventions and codebases would be a mess for all involved.
Years ago I moved from_underscores toCamelCase but I'm not vehemently passionate about it and there are plenty of cases where I need to go back to match_conventions.
Re:CamelCase vs. underscores: Scientific showdown
by untog on Tuesday March 03, 2015 @11:45AM
(#9138669)
Well, sure, when part of a team, make a decision and go with it. But most of the time these debates on HN just disappear down a hole of people arguing past each other and caring far too much about something that doesn't matter.
Re:CamelCase vs. underscores: Scientific showdown
by wvenable on Tuesday March 03, 2015 @01:38PM
(#9139626)
I said CamelCase but depending the code base I'll use underscores. It almost has no affect on my brain anymore; I can read both easily.
I like using CamelCase for most things because it gives the option of also using underscores on top of that. For example, for database and table names, I'll use CamelCase for names but underscores for primitive namespacing.
Re:CamelCase vs. underscores: Scientific showdown
by 64bitbrain on Tuesday March 03, 2015 @12:17PM
(#9138910)
When I am writing C, I tend to use underscore. I think I just follow the convention, or the code that already exists. Imagine the some part of the code written in camelCase and other used underscore.
Re:CamelCase vs. underscores: Scientific showdown
by exogen on Tuesday March 03, 2015 @12:34PM
(#9139090)
Camel case results in several sources of frustration for me:
1. Is it userID or userId? HTTPClient or HttpClient? Leaving this additional stylistic choice up to people results in conflicting styles even within the scope of "camel case" everywhere! (JavaScript mostly leaves them uppercase, e.g. DOMException...then there's XMLHttpRequest...)
2. Code isn't the only place we need to make this choice: what about configuration files? I find that using camel case for configuration keys – even if the configuration will be the input to a camel-case-language program! – just feels incredibly wrong.
Re:CamelCase vs. underscores: Scientific showdown
by Someone on Tuesday March 03, 2015 @02:30PM
(#9140019)
I would like to see whether mother tongue has an effect on preference. Languages with lots of compounding (http://en.m.wikipedia.org/wiki/Compound_(linguistics) such as German and Dutch or languages without many spaces such as Classical Latin and Greek, Egyptian hieroglyphics and, sort-of, Chinese and Japanese might make CamelCase look more familiar. I know of one data point: Guido van Rossum is Dutch, and underscores are fairly common in Python (but, on the other hand, https://docs.python.org/3/library/functions.html has 'isinstance', 'setattr' and 'memoryview')
And, by the way, middle-score as in lisp (and, from there, Dylan and Clojure) is the superior approach: easier to type than either, and makes you stand out from the crowd :-)
Re:CamelCase vs. underscores: Scientific showdown
by olav on Tuesday March 03, 2015 @12:55PM
(#9139261)
In my eyes, using CamelCase is a kind of cargo cult, based on the fact that the programming language Smalltalk used it. C++ adopted the style and moved away from the predominant use of underscores in C. So, people who want to be seen as modern and object-oriented, are biased to use CamelCase to stress their competence in things OO.
Re:CamelCase vs. underscores: Scientific showdown
by dicroce on Tuesday March 03, 2015 @12:02PM
(#9138798)
I use the convention of the language or large code base I'm working with...
That said, I've found that the style isn't nearly as important as consistency. Generally speaking, an inconsistently styled code base is a sign that the developers didn't really care about their work...
If you follow the normal Lisp pattern of mostly one case and '-' for separation, allowed because Lisps/s-expressions allow the use of the normally reserved '-', I think you get the clearest code. See Clojure for a Lisp that breaks up the sea of Lots of Irritating Sets of Parenthesis if that bothers you.
Re:CamelCase vs. underscores: Scientific showdown
by slm_HN on Tuesday March 03, 2015 @11:46AM
(#9138674)
I find that I view camelCase as one word and camel_case as two words. The '_' works as a separator not a joiner. Since we can only keep four or five words in our working memory it's better for me to use camelCase.
It's possible that with more exposure to underscore_case I would eventually start treating it as one word.
Re:CamelCase vs. underscores: Scientific showdown
by logfromblammo on Tuesday March 03, 2015 @11:44AM
(#9138649)
I can easily write a tool to automatically convert CamelCasedVariables to underscored_variables, or vice versa. The fact that I have not done so indicates that I don't care.
The important thing is that the variable names be chosen to facilitate human understanding of the code.
Re:CamelCase vs. underscores: Scientific showdown
by jgrowl on Tuesday March 03, 2015 @12:18PM
(#9138919)
Would it be possible to just have the editor display to the user whatever style they prefer but keep the underlying representation consistent? I guess it would just add complexity and make it harder to just edit the files as plain text though. Probably not worth.
Re:CamelCase vs. underscores: Scientific showdown
by G3E9 on Tuesday March 03, 2015 @12:43PM
(#9139157)
I use camel case when the subject needs two words in order to identify it. Underscores, I feel, can be used to separate and include multiple ideas within a single name, in order to explain or emphasize on a relationship.
Re:CamelCase vs. underscores: Scientific showdown
by tzs on Tuesday March 03, 2015 @03:14PM
(#9140376)
I've often wanted spaces in C. Because C makes heavy use of required punctuation, there aren't many places that a keyword can be adjacent to an identifier, or two identifiers can be adjacent, so for the most part I don't think spaces would introduce ambiguity.
Offhand, I can only think of a couple problem areas (but my C language lawyer days are long gone and I'm way out of practice--anyone else have some I'm missing?).
1. "goto foo;" could either be a goto keyword and the label foo, or a really stupid expression involving the variable "goto foo".
2. "int foo();" could be a forward declaration of the function foo, or an invocation of the function "int foo".
There would also be some questions about preprocessing. If I have something like "x pos = 12;", and I have a #define pos foo" in effect, does that apply to the "pos" in my "x pos"?
Re:CamelCase vs. underscores: Scientific showdown
by murbard2 on Tuesday March 03, 2015 @12:07PM
(#9138834)
An argument pro underscore: they can be displayed with 50% transparency, making them visible, yet not interfering with the reading of the identifier as much.
There isn't a significant loss in velocity in adapting to use one or the other or even simultaneously (front_end_javascript, BackEndJava, SELECT * FROM blah). The most significant portion of my time is spent thinking/designing/debugging; I save the balls-to-wall frantic keyboard banging for NCIS cameos.
That's the non-starter for me right there. I use whatever convention makes sense in the context of what I'm doing. Language, library and previous code in an existing project all dictate my choice in this matter.
> Camel case is easier to type, and underscores are hard to type.
I'll grant it that, but in the context of programming, this does not seem to be a "pro". After all, don't we spend far more time reading code than we do writing code?
I'm old, but I'm still surprised at how I have to fight over my reluctance to do something in another language (such as Python) when I remember that it's conventionally camelCase...on the other hand, I try to use it as a personal advantage...I can immediately tell in a body of code what helper functions originated from me, as I'll habitually write them in underscore (though this probably annoys the shit out of anyone who then tries to read/use my code).
Conversely, my enthusiasm for using R jumped when I read Hadley Wickham's style guide and saw that he endorsed underscores (http://r-pkgs.had.co.nz/style.html)
According to pep8 "Function names should be lowercase, with words separated by underscores as necessary to improve readability. mixedCase is allowed only in contexts where that's already the prevailing style"
Lisps, by not reserving '-', and following convention:
Also see my other comment.Man, Algol 68 was really ahead of its time... too bad it never caught on.
Observe:
Versus yours: I would be, perhaps, moderately ticked off to have to have to deal with code that looked like that, and used both, in a real world scenario.Among the many reasons I prefer Dvorak is that dash/underscore is on the home row.
I have found it very useful to use under_scores as a form of punctuation within camelCase to visually connect related variables.
Like this:
... and so forth.(Note that the opposite doesn't work: camelCase as a punctuation within under_scores.)
Also, the expression "scientific showdown" about studies that rely on psychological self-reporting is a bit of a stretch.
I personally favour the C-style fuck-it-all naming scheme:
The narrower the columns, the easier it is for me to comprehend the algorithm. It also makes for great method names. Say "isatty" three times; it's fun, isn't it?// BTW: I don't believe anyone telling me they can read camels more efficiently. Underscores add contrast, which aids your vision quite a bit.
Maybe it's time to accept that other people have different opinions to you, and maybe, just maybe have a preference for camel-casing.
I'm glad you used the word "preference." I wish people wouldn't feel the need to justify arbitrary choices they make in life. It's your code and I will honour the choices you made if I ever end up working on it. You can't expect me to drink the Kool-Aid though.
Are we discussing Pascal casing now? ;)
> There is an objective, scientific truth to which one is easier to read
I seriously doubt that. I would have thought that training over many years creates a bias one way or the other. I find It_might_be_this_one much harder to read than itMightBeThatOne. I much prefer kebab-casing-over-underscores also.
Perhaps there's a definitive answer for new programmers who have never seen either casing style? But for you to claim that those who disagree with you are drinking Kool-Aid is disingenuous.
- CamelCase 52.34% (4,493 votes)
- underscores 47.66% (4,092 votes)
Which kind of says it all. Use whatever style you want, stop worrying so much about what other people are doing. Variable names a far more important than the formatting you use with them.
If organizations allowed that you'd have no conventions and codebases would be a mess for all involved.
Years ago I moved from_underscores toCamelCase but I'm not vehemently passionate about it and there are plenty of cases where I need to go back to match_conventions.
Citation needed; my experience is just the opposite (it works much better than trying to specify some kind of organization-wide standard).
I like using CamelCase for most things because it gives the option of also using underscores on top of that. For example, for database and table names, I'll use CamelCase for names but underscores for primitive namespacing.
- CamelCase 43.84% (1,117 votes)
- underscores 56.16% (1,431 votes)
The beginning poll still is still within half a percent of your numbers as of now.
Apparently, people who prefer underscores are more likely to follow through. ;)
Or perhaps they're predisposed to underscore their arguments. :)
//This wont look good :)
int static set_my_config(char* data);
int static getMyConfig();
1. Is it userID or userId? HTTPClient or HttpClient? Leaving this additional stylistic choice up to people results in conflicting styles even within the scope of "camel case" everywhere! (JavaScript mostly leaves them uppercase, e.g. DOMException...then there's XMLHttpRequest...)
2. Code isn't the only place we need to make this choice: what about configuration files? I find that using camel case for configuration keys – even if the configuration will be the input to a camel-case-language program! – just feels incredibly wrong.
And, by the way, middle-score as in lisp (and, from there, Dylan and Clojure) is the superior approach: easier to type than either, and makes you stand out from the crowd :-)
That said, I've found that the style isn't nearly as important as consistency. Generally speaking, an inconsistently styled code base is a sign that the developers didn't really care about their work...
So an underscore function can not (easily) be modified to suit a particular function since it's used all over the place.
But a camel case function can be modified because it is only used in the same part of the program, so you can easily change all uses of it.
It's possible that with more exposure to underscore_case I would eventually start treating it as one word.
The important thing is that the variable names be chosen to facilitate human understanding of the code.
country_state_city
or
unitedStates_texas_houston
or
unitedStates_newMexico_santaFe
edit: sorry, don't know HN's markup
Offhand, I can only think of a couple problem areas (but my C language lawyer days are long gone and I'm way out of practice--anyone else have some I'm missing?).
1. "goto foo;" could either be a goto keyword and the label foo, or a really stupid expression involving the variable "goto foo".
2. "int foo();" could be a forward declaration of the function foo, or an invocation of the function "int foo".
There would also be some questions about preprocessing. If I have something like "x pos = 12;", and I have a #define pos foo" in effect, does that apply to the "pos" in my "x pos"?
That, and it's easier to type (reduction of combo-pressing shift and the key for _)
1. http://en.wikipedia.org/wiki/CamelCase