Let's analyze underscores vs BiCapitalization and see what we can find.
SomeProc(ThisHere(ThatVar - ThatThere));
SomeProc(ThisHere(ThatVar - ThatThere));
SomeProc(ThisHere(ThatVar - ThatThere));
some_proc(this_here(that_var - that_there))
some_proc(this_here(that_var - that_there))
some_proc(this_here(that_var - that_there))
Many argue that underscores_are_easier_to_read_because_they_are_more_like English prose.
People who argue this are people like:
The problem is.. programs are not prose. Programs, are source code. Source code does not contain just english_sentences_like_this_here it instead contains brackets, symbols, whitespace, etc. which already spread out code quite a bit.
In the above snippets, we could have a hard time finding the minus sign with all the underscore pollution. I call it pollution because underscores are just another symbol.. and code already contains plenty of symbols. Do we need more symbols with code that already contains plenty of symbols? I'm not trying to be religious or derogatory.. but if you study the above example, you can maybe see my point when I use the word pollution. Do we need the extra fumes and smog in the code?
In the above code snippet we see lots of underscores... and brackets, and a minus sign, and a bit of white space. But are we getting the code across to the person reading the code.. or are we bloating the reader with symbols? We've got underscores everywhere, brackets, and minus sign.. but where is the code?
I find that sometimes underscores can spread out the code, but other times I find it bloats it up with useless symbols. Code already contains lots of symbols and separators.. like brackets, spaces, plus signs, and minus signs.. so WeldingTheFunction together helps WeldTheFunction together instead of separating it and mixing it in with more symbols such as the minus sign and whitespace.
Underscores can be confused with minus signs and whitespace at times, or they can just add more needless spacing to an already spaced out program (casts, carriage returns, and arithmetic operators space out the program enough already).
Maybe adding underscores adds more symbols to an already symbol infested source file?
Should we preserve the underscore for special situations like below?
TCP_IP_LibraryFunction
Instead of the problematic
TCPIPLibraryFunction
Or we could go
TcpIp_LibraryFunction
The Ada Style
Then there is the Ada style:
Some_Proc(This_Here(That_There - This_Other))
I find the Ada style a not much easier to read than all lower case underscores.. but maybe a little depending on how you look at it and what day it is ;-)
Any underscore advocate can argue that This_Is_Easy_To_Read_In_English but I once again remind the advocates that code is not English. Code contains symbols and arithmetic and brackets.. which space the code out plenty already.
Whitespace and More Whitespace
Then if you add some 8 space indentations into the code you get even more white space. I suppose someone would argue that whitespace is GOOD.. but I guess what I'm arguing is that if I have a lot of symbols and whitespace all over my code anyway, and a lot of brackets in my code.. then adding more symbols isn't going to necessarily make the code more readable. And, an underscore is just another symbol..yes.
Do We Need Scientific Studies To Help
So the arguments that this_is_easier_to_read_because_it_is_more like a novel or essay is not scientific. It is more a straw man argument. It is a straw man argument because code is not English. Code is Code. Code is a completely different beast than English. Code already contains symbols and brackets. Code already contains a lot more symbols and brackets than English text, and adding underscores adds even more symbols to an already symbol infested mixture.
We can't just start comparing English to Code as if they can be scientifically compared equally - and I see a lot of people arguing this way.
Psychology, Analysis, and Reasoning
What I'm trying to do? I'm trying to find scientific reasoning behind coding styles. I think a lot of people who argue about coding styles aren't thinking scientifically enough.. because when I see arguments about coding styles we always hear these same straw man arguments that appear to be correct on the surface. That's be cause these straw men pull in incomplete evidence such as
ThisIsHarderToReadBecauseItUsesMixedCaseStyle
But the reality is, code already contains brackets and other symbols so
ThisIs(NotAlways(Harder - ToRead + SinceCode + Is / NotEnglish));
So the next time you are in an argument about coding styles.. don't use straw man arguments.. and don't try to be religious. Try and think a bit about what code contains lots of. Messy code like perl contains lots of symbols. So I guess to neaten code we some how have to find a fine balance.
Not that I'm a super favorite of ThisStyleHere.. I'm actually fond of dashes the way lisp does it, or even dashes with mixed case. I'm not super against underscores but they are ugly at times.
I considered this-style and This-Style (dashes, the lisp way) for my programming language invention. I haven't made the final decision yet though as that interrupts the language's math capabilities (the minus operator would be replaced with the letter 'm' possibly, not liked by some people, in order to parse identifiers with dashes).
There is something about underscores that make them ugly but I can't put my finger on it. It is the way they stick out in code. Dashes are more aesthetically pleasing in some ways. Some people argue that dashes ram the text too close together.. but they only ram the text closer than underscores if you are using a font that isn't fixed width. And I still find dashed functions okay to read even when not using a fixed font.
We could argue that using two underscores or three underscores help us read code easier...
this___is___easy___to___read.
But the question is, does this actually help us write clean code or does it just pollute our source code with underscores jumping out everywhere? Again, my theory is that code already has enough symbols in it, and underscores just add more symbols to the already symbol heavy code.
Underscore For Special Code
It is as if the underscore is an operator and it is emphasizing that we are doing something special - when in fact we are not. Therefore the underscore jumps out at us. This can be used cleverly, to cause code to jump out where we want it to.. but once you have the entire source file filled with underscores here and there, they no longer become a powerful tool.
Do Underscores Crowd Lines?
Another scientific possibility could be that underscores crowd the code lines beneath them a bit:
t_something
this_function
ThatSineClass
Above the underscore crowds the 'S' since the u nderscore is nearly touching the 'S'. The underscore also comes close to touching the 'h'. This could be the aesthetics problems with underscores.. since they crowd the line spacing and they jump below and above text.
Double Click and Hyperlink
Another issue is double-clicking functions. I like to double click functions so I can select the entire function. In many editors, when you double click on underscored stuff, the entire function does not become selected. This is a documentation issue when you wish to doubleclick and find docs on it using google quickly. You don't want to have to play around with your mouse just to select the function_with_uscores so that you can paste it into a search engine.
Some editors are configured or programmed around this problem - but the point is that many editors are not. The dashed functions will probably have the same problem (I'm trying to not be too biased here, I'm not saying dashes are infinitely better).
Another issue with underscores is that in hyperlinks for the web, you can't tell whether the underscore is really there or not consider this_example_that_links_nowhere. Can you tell if there are underscores or spaces between the words? So in html documentation it could lead to confusion since you are not sure if there are spaces or underscores in hyperlinks. A solution would be to remove the underlining using style="text-decoration:none" in CSS for hyperlinks, though. But this breaks the standard web rules of links being underlined.
|