25

Possible Duplicate:
Parameter naming: filename or fileName?

What do you use - filename or fileName? The classes in the JDK use a lower case 'n', e.g. FilenameFilter, so, for consistency, I do too. But the correct way, I believe, should be fileName (as in C#).

Community
  • 1
  • 1
dogbane
  • 266,786
  • 75
  • 396
  • 414

5 Answers5

25

I'd base that decision on the surrounding identifiers.

If filename is the only identifier regarding files in its context, I'd stay with that.

Example:

public void load(String filename) { ... }

But as soon as you have other file attributes I'd consider using this:

private String fileName;
private long fileSize
private DateTime fileAge;
Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
  • 25
    This makes no sense. You start with single field called filename. And a few weeks later you add fileSize. Then you need to rename the old field. – Heiner May 29 '18 at 14:29
9

my dictionary says "filename" so i'd keep using a lowercase "n": http://dict.leo.org/?search=filename

stmax
  • 6,506
  • 4
  • 28
  • 45
  • Great to have a link to a good dictionary. I always want to camelize according to the actual spelling. The hard thing is usually to find the correct spelling. Leo says "filename", so that's it. Leo also says "field name", which is great because I always spell it "fieldName". – Michael Nov 21 '19 at 10:15
8

The real question is whether the thing is called "file name" or "filename".
The rest is then a trivial matter.

The Wikipedia article is filename, even though the content has both "file name" and "filename".

Personally I vote for "filename".

RichN
  • 6,181
  • 3
  • 30
  • 38
4

filename

Like you, I do it to be consistent with the Java libraries.

Kris
  • 14,426
  • 7
  • 55
  • 65
2

I'm not really consistent, but I tend to use "filename", even though fileName would be more grammatically correct since "file name" is two words, not one.

JesperE
  • 63,317
  • 21
  • 138
  • 197