Parameter naming: filename or filename?

I am trying to be grammatically correct in my title *. I always used filename instead of filename . This seems to be a java convention, but FxCop prefers filename .

The discussion on WikiPedia is discussed here. The more I read, the more I feel that I'm right (this is pretty ordinary! :)). Does anyone have a definitive answer or is it just something subjective?

* I just hope there are no grammar errors in this post!

+50
naming-conventions naming fxcop
Apr 12 '09 at 17:55
source share
8 answers

The lower camel area is recommended for fields and parameters.

Example 1 :

 fileName // for fields, parameters, etc. FileName // for properties, class names, etc. 

Commonly used are fileName and NOT fileName ; you can make sure that by reading the source code of the open source material created by Microsoft, such as the corporate library .

Causes

  • the main point is that the names in this case are more readable.
  • Also this approach adds consistency when several parameters (fields, variables ..) are used in the same method (class ..) and with the same file prefix, as shown below:
  • ... there are several other reasons, but they are more subjective.

Example 2 :

 fileName, fileSize... // instead of filename AND filesize 

See also :

For a complete set of naming convention rules, I recommend checking out this book:

And also check out some things on IDesign.net

+28
Apr 12 '09 at 17:57
source share

'filename' suggests that this word describes a particular object, such as โ€œcowโ€ or โ€œchairโ€
'filename' assumes that it is a complex object, there is an object named file and this object describes the name of this file.

Two philosophical approaches, take your choice.

+22
Apr 12 '09 at 18:01
source share

As I know,

thisIsMuchMoreReadable than readingthis.

+9
Apr 12 '09 at 17:59
source share

I think the answers here cover two questions.

  • 'FileName' vs 'Filename' (should โ€œnameโ€ be a separate word)

    and

  • 'fileName' vs 'FileName' (the first character is lowercase).

In most cases, I prefer to consider this word as one whole word "file name". I also prefer to start lowercase variables / methods to make it easier to navigate the code completion menu.

I think that the problem with the camel case is also here, and I think that it should be used to indicate verbose names.

+7
Apr 12 '09 at 18:18
source share

Not an obvious answer that FxCop is an automated tool? He admits that โ€œnameโ€ is a word, therefore, it suggests starting it with capital N. We know that โ€œfile nameโ€ is also a word, and therefore only the first F. should be blotted out.

+3
Apr 12 '09 at 18:05
source share

Filename ~ identifying name assigned to an electronic computer, in accordance with the restrictions imposed by the operating system, such as length or limited selection of characters.

In the past, this was considered two words, but now it is defined as one word, therefore

var filename = ......

If it were two words, it would be

var fileName = ....

+2
Apr 22 '16 at 10:01
source share

There can be no real or wrong.

This is something that is purely subjective and fully refers to the community in which you work. If FxCop and StyleCop and the .net code you regularly encounter use fileName, then use fileName. If he uses something else, then use all that is.

Your first priority should probably be consistent with the template in your own code, and then fit your community.

In this particular case .net Reflector shows a lot of .net code using fileName, so I would go with this template personally.

If you were in the java world and ran PMD and checkstyle, and their apis often used the file name, then I would go with that.

In addition to the Wikipedia article, there is also Kernigan and Pike programming practice. The first chapter in it addresses many of the problems with naming and code negotiation.

+1
Apr 12 '09 at 18:11
source share

If you write c / C ++, there is a strong tendency to use names that people can actually read; that is, the file name is good, and thus it is still the file_domain_name (if you do not consider the file name as the correct English word - I usually do).

See Google Coding Standards

0
Apr 12 '09 at 20:13
source share



All Articles