Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter naming: filename or fileName?

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!

like image 900
Steve Dunn Avatar asked Apr 12 '09 17:04

Steve Dunn


People also ask

What is the best naming convention for files?

File naming best practices:Avoid special characters or spaces in a file name. Use capitals and underscores instead of periods or spaces or slashes. Use date format ISO 8601: YYYYMMDD.

Should I use dashes or underscores in filenames?

Guidelines for names Make file and directory names lowercase. Use hyphens, not underscores, to separate words—for example, query-data.

Should file names be camel case?

Human readableWord boundaries in the file name can be indicated by using medial capitalization called camel case, for example “FileName”, or underscore, for example “file_name”. File names should not have any spaces or other special characters.

What is naming convention for FileName?

A File Naming Convention (FNC) is a framework for naming your files in a way that describes what they contain and how they relate to other files. Developing an FNC is done through identifying the key elements of the project, the important differences and commonalities between your files.


3 Answers

Lower camel case is recommended for fields and parameters.

Example 1:

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

Generally, fileName is used and NOT filename; you can verify that by reading source code of open source stuff created by Microsoft, such as Enterprise Library.

Reasons:

  1. The main point behind this is that names are more readable in this case.
  2. Also this approach adds consistency when several parameters (fields, variables..) are used in the same method (class..) and the with same prefix "file", as demonstrated below:
  3. ...there are a few other reasons, but they are more subjective.

Example 2:

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

See also:

  • Naming Conventions at Wikipedia
  • General Naming Conventions at MSDN

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

  • Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries
    (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

like image 153
14 revs, 3 users 94% Avatar answered Oct 17 '22 09:10

14 revs, 3 users 94%


'filename' assumes that this word describes a singular object like 'cow' or 'chair'
'fileName' assumes that this is a complex object, that there is an object called file and that this object describes the name of that file.

Two philosophical approaches, take your pick.

like image 28
shoosh Avatar answered Oct 17 '22 08:10

shoosh


It is acceptable English to write "filename" or "file name". When you translate that into coding, capitalizing the "n" or not capitalizing the "n" can go either way (assuming camelCase or PascalCase).

By the way, you did make a grammatical error in the question--ironically, in the very sentence in which you were expressing your hope that there were no grammatical errors. You said, "I just hope there's no grammar errors in this post!" But "errors" is plural, therefore the "is" of "there's" represents a subject-verb disagreement.

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

like image 18
mannyglover Avatar answered Oct 17 '22 10:10

mannyglover