Live data from Hacker News

CamelCase vs. underscores: Scientific showdown

whathecode.wordpress.com

51–60 of 60 posts

Re: CamelCase vs. underscores: Scientific showdown

#51
I use both. I use underscore for global functions, and camel case for functions specific to the module.

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.

Re: CamelCase vs. underscores: Scientific showdown

#52
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

#53
post #42

Earlier quoted context omitted.

> // BTW: I don't believe anyone telling me they can read camels more efficiently. Maybe it's time to accept that other people have different opinions to you, and maybe, just maybe have a preference for camel-casing.

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 expec…

> 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

#54
post #3

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.

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

#55
post #53

Earlier quoted context omitted.

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 expec…

> 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…

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

#57

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. if(Accounts_Orders_Invoices_Table.Order_Invoice_Number == Order_Invoice_Number){ ...} if(AccountsOrdersInvoicesTable.OrderInvoiceNumber == OrderInvoiceNumber){ ... } But I don't really care that much. I'll just do whatever everyone else is doing. At l…

Your first example is actually a mutant hybrid of camel-cased underscores. Observe: if(accounts_orders_invoices_table.order_onvoice_number == order_invoice_number){ ...} Versus yours: if(Accounts_Orders_Invoices_Table.Order_Invoice_Number == Order_Invoice_Number){ ...} 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.

Fair point. That was more my laziness in creating the fictional example (I just added the _ to the camelCase).

Re: CamelCase vs. underscores: Scientific showdown

#58
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

#59

Is there some reason we can't just do away with both and consider spaces in languages?

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

#60

Very often a variable name needs to provide more context. I have found it very useful to use under_scores as a form of punctuation within camelCase to visually connect related variables. Like this: spectrumPlot_x spectrumPlot_y spectrumPlot_drawHarmonics qa_signalDone qa_setLoadedFlag requestTimeout_minValue requestTimeout_maxValue ... and so forth. (Note that the opposite doesn't work: camelCase as a punctuation wit…

In c often I use underscores to deal with lack of name spaces and or classes. As in Module_FunctionName()
Post reply on HN