Parameter naming: filename or fileName?

2019-02-03 21:08发布

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!

9条回答
在下西门庆
2楼-- · 2019-02-03 21:56

Isn't the obvious answer that FxCop is an automated tool? It recognizes that "name" is a word, so it suggests starting it with a capital N. We happen to know that "filename" is also a word, and so only the first F should be capitalized.

查看更多
老娘就宠你
3楼-- · 2019-02-03 22:00

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!

查看更多
Explosion°爆炸
4楼-- · 2019-02-03 22:04

'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.

查看更多
登录 后发表回答