Parameter naming: filename or fileName?

前端 未结 9 2041
情歌与酒
情歌与酒 2020-12-29 19:26

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

9条回答
  •  佛祖请我去吃肉
    2020-12-29 19:49

    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

提交回复
热议问题