I try to be grammatically correct in my naming*. I've always used filename
instead of fileName
. The java convention also seems to use this, but FxCop prefers fileName
.
There's a discussion on WikiPedia about it. The more I read, the more I feel I'm right (which is quite usual! :) ). Does anyone have a definitive answer or is this merely something subjective?
* I just hope there are no grammar errors in this post!
I think the answers here are spanning two issues.
'FileName' vs 'Filename' (should 'name' be a separate word)
and
'fileName' vs 'FileName' (should first character be lower case).
In most cases, I prefer to treat this word as a single whole word 'filename'. I also prefer starting variables/methods with lower case for easier code completion menu navigation.
I guess the issue of camel case is here too which I think should be used to distinguish multi-word names.
Lower camel case is recommended for fields and parameters.
Example 1:
Generally,
fileName
is used and NOTfilename
; you can verify that by reading source code of open source stuff created by Microsoft, such as Enterprise Library.Reasons:
Example 2:
See also:
For a full set of naming convention rules, I recommend checking this book:
(2nd Edition) by Krzysztof, published on Nov, 2008
(personally we don't use 100% recomendations from this book, but in overall there are pretty good guidelines)
And also check some stuff at IDesign.net
Filename ~ an identifying name given to an electronically stored computer file, conforming to limitations imposed by the operating system, as in length or restricted choice of characters.
In the past this was considered two words but now is defined as one word so
var filename = ......
if it was two words it would be
var fileName = ....
There can be no real right or wrong here.
This is something that is purely subjective and relates completely to the community you are working in. If FxCop and StyleCop and the .net code that you regularly encounter is using fileName, then use fileName. If it is using something else, then use whatever that is.
Your first priority should probably be to be consistent to the pattern in your own code and then consistent with your community.
In this particular case, .net Reflector shows a lot of .net code using fileName so I would go with that pattern personally.
If you were in the java world and running PMD and checkstyle and their apis made frequent use of filename, then I would go with that.
In addition to the wikipedia naming article, there is also The Practice of Programming by Kernighan and Pike. The first chapter in it touches on a lot of naming and code consistency issues.
As far as I am concerned,
If you are writing c/c++ there is a strong tendency to use names that people can actually read; i.e. filename is good, and so is yet_another_file_name (assuming you are not considering filename as a proper english word - I usually do).
See google coding standards