Underscores vs CamelCase

Please compose all posts in Emacs.

Moderators: phlip, Prelates, Moderators General

Underscores vs CamelCase

Postby Doodle77 » Tue Dec 04, 2007 12:51 am UTC

I have honestly never been sure which to pick. Many a time have i changed the names of functions i had written previously to conform to whatever inane rule my current code was following.
I need convincing.
Doodle77
 
Posts: 106
Joined: Mon Mar 26, 2007 9:46 pm UTC

Re: Underscores vs CamelCase

Postby JayDee » Tue Dec 04, 2007 12:54 am UTC

Look at my UserName and guess which I pick.
User avatar
JayDee
 
Posts: 3620
Joined: Sat Nov 10, 2007 3:13 am UTC
Location: Most livable city in the world.

Re: Underscores vs CamelCase

Postby crazyjimbo » Tue Dec 04, 2007 1:08 am UTC

JayDee wrote:Look at my UserName and guess which I pick.


And look at mine and guess which I pick :P

I use CamelCase for classes and such like, and underscores for variables and methods. In a non OO language (i.e. C for me), I go with underscores for pretty much everything, but I haven't programmed in this for a while now.
User avatar
crazyjimbo
 
Posts: 887
Joined: Fri Apr 20, 2007 11:45 pm UTC
Location: Durham, England

Re: Underscores vs CamelCase

Postby photosinensis » Tue Dec 04, 2007 1:28 am UTC

I'm a fan of CamelCase myself, particularly for classes and functions. Objects and primitives usually get names in linguam latinam. This has caused amusement amongst profs that knew what I was doing and confusion amongst those that didn't.

I hate underscores with the fire of a thousand large, non-visible spectrum stars. HATE THEM.
While I clicked my fav'rite bookmark, suddenly there came a warning,
And my heart was filled with mournng, mourning for my dear amour.
"'Tis not possible!" I uttered, "Give me back my free hardcore!"
Quoth the server: 404.
photosinensis
 
Posts: 163
Joined: Wed Aug 22, 2007 6:17 am UTC

Re: Underscores vs CamelCase

Postby b.i.o » Tue Dec 04, 2007 1:34 am UTC

I use CamelCase almost exclusively. Underscores annoy me.
User avatar
b.i.o
Green is the loneliest number
 
Posts: 2520
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Re: Underscores vs CamelCase

Postby crazyjimbo » Tue Dec 04, 2007 1:37 am UTC

i_find_it_is_much_easier_to_read_something_in_underscores_than_in_camel_case.

ButThenAgainThatMightJustBeMe,YouShouldAllLetMeKnowWhatYouThink.
User avatar
crazyjimbo
 
Posts: 887
Joined: Fri Apr 20, 2007 11:45 pm UTC
Location: Durham, England

Re: Underscores vs CamelCase

Postby ++$_ » Tue Dec 04, 2007 1:39 am UTC

Underscores require an extra keystroke to type. Therefore, they are inferior.

Why is there even any debate about this?

Anyway, you could write a perl script to convert between them in case your Current Project requires you to use the other convention.

Note: In Lisp, where dashes are allowed in variable names, that becomes the preferred option (at least for me). For example:
variable-with-long-complex-name instead of VariableWithLongComplexName. Far superior (same number of keystrokes, too!). Too bad that most languages overload - to mean "minus."

EDIT: It just occurred to me that this problem doesn't even exist if you write all your code in German (because you can just use compound words). Let's start a movement.
++$_
Mo' Money
 
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: Underscores vs CamelCase

Postby JayDee » Tue Dec 04, 2007 1:42 am UTC

Not really much of a difference. Even less of a difference in readability, I'd assume, if we are talking a couple of words rather than an entire sentence.
User avatar
JayDee
 
Posts: 3620
Joined: Sat Nov 10, 2007 3:13 am UTC
Location: Most livable city in the world.

Re: Underscores vs CamelCase

Postby zenten » Tue Dec 04, 2007 1:53 am UTC

Camel Case is a tool of Microsoft.
zenten
 
Posts: 3798
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Underscores vs CamelCase

Postby EvanED » Tue Dec 04, 2007 1:54 am UTC

Me? I'm agnostic. I use UpperCamelCase for classes, and lowerCamelCase for functions and variables. UPPER_UNDERSCORE_CASE is for macros. (Constants that aren't macros follow the lowerCamelCase variant. I reserve UPPERCASE for macros.)

++$_ wrote:Underscores require an extra keystroke to type. Therefore, they are inferior.

Why is there even any debate about this?

Because, as crazyjimbo said, underscores are easier to read.

Anyway, you could write a perl script to convert between them in case your Current Project requires you to use the other convention.

Unless it's the convention crazyjimbo mentioned. Then your perl "script" is going to become fairly complicated. ;-)

(Probably still doable though... hmm, may not even be *that* hard now that I think about it a little more.)

Note: In Lisp, where dashes are allowed in variable names, that becomes the preferred option (at least for me). For example:
variable-with-long-complex-name instead of VariableWithLongComplexName. Far superior (same number of keystrokes, too!). Too bad that most languages overload - to mean "minus."

Agreed! Easier to type, better looking, and just as easy to read as underscores.
EvanED
 
Posts: 4145
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Underscores vs CamelCase

Postby Tuke » Tue Dec 04, 2007 2:51 am UTC

EvanED wrote:Me? I'm agnostic. I use UpperCamelCase for classes, and lowerCamelCase for functions and variables. UPPER_UNDERSCORE_CASE is for macros. (Constants that aren't macros follow the lowerCamelCase variant. I reserve UPPERCASE for macros.)


ButwhatifI'manathiest? ThenwhatdoIdo?
I have a secret to share with you.
Spoiler:
I'm not a moose.

Image
User avatar
Tuke
 
Posts: 30
Joined: Thu Nov 01, 2007 5:30 pm UTC
Location: Saskatoon, Saskatchewan

Re: Underscores vs CamelCase

Postby Korandder » Tue Dec 04, 2007 3:41 am UTC

I use CamelCase, but this is mostly a side effect of learning Java first.
Image
User avatar
Korandder
 
Posts: 161
Joined: Fri Sep 14, 2007 6:12 am UTC
Location: LoadingReadyRun Australian Astrophysical Observatory

Re: Underscores vs CamelCase

Postby davean » Tue Dec 04, 2007 5:04 am UTC

Korandder wrote:I use CamelCase, but this is mostly a side effect of learning Java first.


Other side effects may include Nausea, migraines, constipation, loss of agility, and sudden death.
User avatar
davean
Site Ninja
 
Posts: 2438
Joined: Sat Apr 08, 2006 7:50 am UTC

Re: Underscores vs CamelCase

Postby b.i.o » Tue Dec 04, 2007 6:36 am UTC

crazyjimbo wrote:i_find_it_is_much_easier_to_read_something_in_underscores_than_in_camel_case.

ButThenAgainThatMightJustBeMe,YouShouldAllLetMeKnowWhatYouThink.


I agree when you type out whole sentences in it. But for 2-4 words I find it's just as readable and cleaner looking.
User avatar
b.i.o
Green is the loneliest number
 
Posts: 2520
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Re: Underscores vs CamelCase

Postby photosinensis » Tue Dec 04, 2007 8:52 am UTC

davean wrote:
Korandder wrote:I use CamelCase, but this is mostly a side effect of learning Java first.


Other side effects may include Nausea, migraines, constipation, loss of agility, and sudden death.


Not to mention difficulties with handling I/O. You'd think that taking arguments from standard input would be easy. You would also be very, very wrong. Seriously, I'm thinking I might just create a class that handles inputs and does absolutely nothing else, then use it in all subsequent Java code of mine.

The guy with the messed up bit of mixing camel case and underscores has no clue what he's missing with compound words. As for macros, I'll have to think of something. I'll probably make those in another language, too. However, I've generally found preprocessor macros to be generally annoying. Just write the damn code.
While I clicked my fav'rite bookmark, suddenly there came a warning,
And my heart was filled with mournng, mourning for my dear amour.
"'Tis not possible!" I uttered, "Give me back my free hardcore!"
Quoth the server: 404.
photosinensis
 
Posts: 163
Joined: Wed Aug 22, 2007 6:17 am UTC

Re: Underscores vs CamelCase

Postby Dongorath » Tue Dec 04, 2007 10:04 am UTC

I don't care, I stick to the convention of the code base I'm working on. At my work, it's CamelCase... So when I write personnal stuff, I tend to use CamelCase...
Dongorath
 
Posts: 93
Joined: Tue Oct 16, 2007 1:17 pm UTC

Re: Underscores vs CamelCase

Postby Tei » Tue Dec 04, 2007 10:40 am UTC

CamelCase seems superior. You don't need extra characters and looks clean to me.
I will use whatever is right on the code. if theres already code and use "_", I will use "_".
User avatar
Tei
 
Posts: 64
Joined: Fri Nov 30, 2007 2:58 pm UTC

Re: Underscores vs CamelCase

Postby enk » Tue Dec 04, 2007 11:07 am UTC

++$_ wrote:Underscores require an extra keystroke to type. Therefore, they are inferior.


Well, once, yes. After that, there's something called word completion.
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Underscores vs CamelCase

Postby evilbeanfiend » Tue Dec 04, 2007 11:18 am UTC

generally i prefer underscores, mostly because i don't recognise capitals very easily, and the c++ std library and boost library use underscores. however the usually rules of following the conventions used in the code you edit prevail.
in ur beanz makin u eveel
User avatar
evilbeanfiend
 
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: Underscores vs CamelCase

Postby Kizyr » Tue Dec 04, 2007 12:33 pm UTC

There are a few situations where I prefer underscores. If I'm renaming a whole bunch of files, and separating out words with spaces in the filenames, it's a lot easier to have a standard character to translate into spaces. If it's CamelCase then I may as well have to write an actual program to rename the files instead of just putting together a batch file in five seconds. KF
~Kaiser
Image
User avatar
Kizyr
 
Posts: 2070
Joined: Wed Nov 15, 2006 4:16 am UTC
Location: Virginia

Re: Underscores vs CamelCase

Postby pieaholicx » Tue Dec 04, 2007 12:53 pm UTC

Both in the same program. Yeah, I tend to not prefer a standard, which tends to make people mad. Unless I'm writing Java (which is what my job is using), then I use lowerCamelCase since that was always how I was taught Java, and it just stuck.
It's okay, I'm Chaotic Neutral. I can kill him over the loot.
Overexposure to pieaholicx may, in semi-rare cases, emancipate dental fillings, crowns, tooth enamel, and teeth.
User avatar
pieaholicx
The cake is a lie!
 
Posts: 531
Joined: Mon Oct 22, 2007 12:51 pm UTC

Re: Underscores vs CamelCase

Postby Dingbats » Tue Dec 04, 2007 5:03 pm UTC

Underscores, mostly because it looks more professional to me. :roll:
User avatar
Dingbats
 
Posts: 921
Joined: Tue Mar 20, 2007 12:46 pm UTC
Location: Sweden

Re: Underscores vs CamelCase

Postby HappySmileMan » Tue Dec 04, 2007 6:52 pm UTC

I use lowerCamelCase for functions or variables, UpperCamelCase for classes and CAPITALS for constants or macros (thhough I don't really use macros)
HappySmileMan
 
Posts: 52
Joined: Fri Nov 09, 2007 11:46 pm UTC

Re: Underscores vs CamelCase

Postby Webzter » Tue Dec 04, 2007 7:47 pm UTC

I use lowerCamelCase for variables and fields. UpperCamelCase for methods and classes. I'm debating switching to leading underscores for fields, even though I think they look ugly, because it disambiguates the following for some people:

Code: Select all
public class Person {
   private string _name;
 
   public Person(string name) {
      _name = name;
   }
}
Webzter
 
Posts: 179
Joined: Tue Dec 04, 2007 4:16 pm UTC
Location: Michigan, USA

Re: Underscores vs CamelCase

Postby Karrion » Tue Dec 04, 2007 11:42 pm UTC

Webzter wrote:I'm debating switching to leading underscores for fields, even though I think they look ugly, because it disambiguates the following for some people


That's what this. is for.
Karrion
 
Posts: 92
Joined: Fri Jun 22, 2007 12:14 am UTC
Location: Melbourne, AU

Re: Underscores vs CamelCase

Postby b.i.o » Wed Dec 05, 2007 2:54 am UTC

photosinensis wrote:Not to mention difficulties with handling I/O. You'd think that taking arguments from standard input would be easy. You would also be very, very wrong. Seriously, I'm thinking I might just create a class that handles inputs and does absolutely nothing else, then use it in all subsequent Java code of mine.


Please excuse me while I steal borrow your idea and regain my sanity.
User avatar
b.i.o
Green is the loneliest number
 
Posts: 2520
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Re: Underscores vs CamelCase

Postby Number » Wed Dec 05, 2007 4:07 am UTC

thingsNamedLikeThis for Java, where theDamnClassNamesGoOnForever.giveMeABreakPlease() happens all the time. While underscores would help readability, the Java brainwashers teachers made us name everything with lowerCamelCase. For a serious C++ project, ClassNames get CamelCase - STL makes this even more fun. But when it makes more sense (e.g. word_order) it gets an underscore, probably because it's a compound word/phrase thingy and putting nothing (wordorder/wordOrder) just looks wrong.
Oh, and constants and macros all get underscores and caps.
You live and learn. At any rate, you live.
User avatar
Number
 
Posts: 63
Joined: Thu Aug 02, 2007 5:42 am UTC
Location: Earth. supposedly

Re: Underscores vs CamelCase

Postby evilbeanfiend » Wed Dec 05, 2007 11:04 am UTC

zenten wrote:Camel Case is a tool of Microsoft.


nonsense, its been around as PascalCase since the 70's at least
in ur beanz makin u eveel
User avatar
evilbeanfiend
 
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: Underscores vs CamelCase

Postby Tei » Wed Dec 05, 2007 11:08 am UTC

zenten wrote:Camel Case is a tool of Microsoft.


Maybe you mean MicroSoft?
User avatar
Tei
 
Posts: 64
Joined: Fri Nov 30, 2007 2:58 pm UTC

Re: Underscores vs CamelCase

Postby BurntCornMuffin » Wed Dec 05, 2007 2:54 pm UTC

I use all lower for variables, upper CamelCase for classes, lower camelCase for functions, and all caps for constants.

Underscores only slow me down, especially since I tend to hit + instead.
Image
User avatar
BurntCornMuffin
 
Posts: 106
Joined: Wed Oct 31, 2007 2:31 pm UTC
Location: Pennsylvania

Re: Underscores vs CamelCase

Postby enk » Wed Dec 05, 2007 10:27 pm UTC

BurntCornMuffin wrote:Underscores only slow me down, especially since I tend to hit + instead.


Again, I'd like to speak in favor of advanced editors that do word completion.

If you're willing to learn and actually invest time in getting faster at editing, I can recommend vim. A lot of others do word completion I guess, I just don't know which ones.

But then again, why use a couple weeks or months getting used to a new editor when you can keep using twice the amount of time editing a file for the rest of your life..?


(Edited to answer the OPs question)
I too
crazyjimbo wrote:find_it_is_much_easier_to_read_something_in_underscores_than_in_camel_case.
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Underscores vs CamelCase

Postby ++$_ » Wed Dec 05, 2007 11:28 pm UTC

enk wrote:
++$_ wrote:Underscores require an extra keystroke to type. Therefore, they are inferior.


Well, once, yes. After that, there's something called word completion.
Afterwards, too, depending on how many of your variable names start with the same characters as the one you're trying to type. Since some people use prefixes for variable names, this is a serious issue. For example, if the variables in one part of your program are all named "tf_varname", where tf stands for whatever that module is, then you have to type in "tf_" every time, regardless of word completion. You might argue that it's the prefix causing the problem, not the underscore, and you would be correct. However, some people consider prefixes to be good style.

Also, even if you do have word completion, camelCase never takes MORE keystrokes. (In my own programs that no one else will have to read, ijuststringmultiplewordstogetherlikethis because I don't have any trouble reading it, it saves even more keystrokes, it gets rid of all case and underscore-related issues, and in my opinion it looks nicer in the code.)

BTW, emacs has word completion too.
++$_
Mo' Money
 
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: Underscores vs CamelCase

Postby enk » Thu Dec 06, 2007 12:49 am UTC

++$_ wrote:
enk wrote:
++$_ wrote:Underscores require an extra keystroke to type. Therefore, they are inferior.


Well, once, yes. After that, there's something called word completion.

Afterwards, too, depending on how many of your variable names start with the same characters as the one you're trying to type. Since some people use prefixes for variable names, this is a serious issue. For example, if the variables in one part of your program are all named "tf_varname", where tf stands for whatever that module is, then you have to type in "tf_" every time, regardless of word completion. You might argue that it's the prefix causing the problem, not the underscore, and you would be correct. However, some people consider prefixes to be good style.


In Vim, typing "t" or "tf", then C-p or C-n will suggest all words starting with "t" and "tf" respectively, including tf_var1, tf_var2 and so on.

(Btw. C-p and C-n are looking for previous or next word with the same beginning (it wraps, so it doesn't matter much in small files (and in normal mode C-p and C-n works like in readline (Emacs, Bash and so on)))).

An example:
Spoiler:
Image
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Underscores vs CamelCase

Postby Silverfish » Thu Dec 06, 2007 5:32 am UTC

Korandder wrote:I use CamelCase, but this is mostly a side effect of learning Java first.


Same here. We learned CamelCasing in my first java course, now I use it for most anything other people will read. When writing programs for myself I tend to just do whatever.
User avatar
Silverfish
 
Posts: 30
Joined: Thu Jun 28, 2007 4:43 am UTC

Re: Underscores vs CamelCase

Postby JamesCFraser » Thu Dec 06, 2007 12:58 pm UTC

I find CamelCase is much easier on the eyes. However, this is just down to my personal experience. I think on the plus side it does make you use case consistently, as opposed to a lot of people using inconsistent capitals.

Perosnally, if I read something with underscores, I mentally pause in between words, whereas I can read CamelCase like a normal sentence.
User avatar
JamesCFraser
 
Posts: 32
Joined: Wed Nov 14, 2007 9:47 pm UTC

Re: Underscores vs CamelCase

Postby shash » Thu Dec 06, 2007 3:38 pm UTC

FlexibleCase_is-whatIUse... ;)

That is, underscores if I'm writing non-OO code (even in C++ or python), PascalCase for class names, camelCase for variables and functions.

In .Net, it becomes Pascal for methods (functions and properties), camel for variables because that's the standard in the framework.

Ultimately, depends on the toolkit and the team...
Do not spin this aircraft. If the aircraft does enter a spin it will return to earth without further attention on the part of the aeronaut.
-- first handbook issued with the Curtis-Wright flyer.
shash
 
Posts: 22
Joined: Sat Jul 14, 2007 10:59 am UTC
Location: India

Re: Underscores vs CamelCase

Postby EvanED » Thu Dec 06, 2007 7:08 pm UTC

Here's an interesting question: what do you do with acronyms?

For instance, would you create a class called XMLParser, or take the .Net standards and do it as XmlParser? What about when doing underscores? XML_parser, Xml_parser, or xml_parser?

(Personally, I like XmlParser and either XML_parser or xml_parser. XMLParser I think makes it harder to find the divisions between the "words".)
EvanED
 
Posts: 4145
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Underscores vs CamelCase

Postby _peterb » Thu Dec 06, 2007 11:55 pm UTC

Wrong wrong and wrong.

Follow the code conventions of the language you are using rather than imposing your deluded style on other people who have to read your code.
_peterb
 
Posts: 5
Joined: Fri Nov 16, 2007 1:58 am UTC

Re: Underscores vs CamelCase

Postby zenten » Fri Dec 07, 2007 12:33 am UTC

_peterb wrote:Wrong wrong and wrong.

Follow the code conventions of the language you are using rather than imposing your deluded style on other people who have to read your code.


I'm still allowed to cry if I really hate the coding conventions though, right?
zenten
 
Posts: 3798
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Underscores vs CamelCase

Postby b.i.o » Fri Dec 07, 2007 1:03 am UTC

EvanED wrote:Here's an interesting question: what do you do with acronyms?

For instance, would you create a class called XMLParser, or take the .Net standards and do it as XmlParser? What about when doing underscores? XML_parser, Xml_parser, or xml_parser?

(Personally, I like XmlParser and either XML_parser or xml_parser. XMLParser I think makes it harder to find the divisions between the "words".)


If you're using CamelCase it would be XMLParser, wouldn't it? Not capitalizing all the letters in an acronym is idiotic.
User avatar
b.i.o
Green is the loneliest number
 
Posts: 2520
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Next

Return to Religious Wars

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests