-2

I'm looking for suggestions to file naming convention in a Git repository.

  • The repository is checked out to and committed from client machines with different OS's and locale settings, which may not have exactly consistent letter case sensitivity and character encodings, and behaviors towards some special characters;

  • The repository has files whose file name must contain multiple complete english words for business reasons, for example, some file names must contain home_value, or home-value, or HomeValue rather than some abbreviated form where the complete English words aren't recognizable such as h_v or h-v or HV.

So I am wondering what rules of convention should be set up for the team, to reduce potential issues. A change of convention or an effort of coercing file naming styles later in could be a pain and counter productive. So I'd like to set up as detailed convention as possible from early on. I could then make stewart scripts to automatically validate the code base.

Some initial thoughtlets:

  • some possible formatting conventions I can think of

    foo_bar # use _ as word separator foo-bar # use - as word separator FooBar # use CamelCase

  • some of the files are HTML files that will be served on web server.

  • always use ASCII characters

  • non-ASCII characters should be converted to Unicode code, for example U+12345

  • always use lower case, e.g. foo_bar but not Foo_Bar or FooBar, to avoid conflict between two files named foo_bar and Foo_Bar. The possible issue with this is that some complete English word I mentioned above are proper nouns and needs to have capitalized initial letter. If the information is lost in the file name, it will need to be stored in some other way.

  • If lowercase letter is always used, then CamelCase is not an option

  • Some complete English words can have - in it, for example some English names, so it seems the foo-bar style is not an option. The only left possibility is foo_bar?

  • If I then allow capital letter to accomodate proper nouns, then in general, a file name is

    foo_Bar_FooBar

But is it a good idea?

4

1 に答える 1

1

The only real technical challenge is that Unicode filenames are poorly supported. They generally are non-portable and can cause some bizarre problems. Another problem is that Windows is case-insensitive and Unix-based OS's aren't. This means that you can create files named HomeValue and homevalue next to each other on a Mac or Linux computer, and that will cause problems when you move to Windows.

My recommendation is to use ASCII letters, and don't have two names that are the same except for case. As for word separation, spaces should work just fine. There's no reason to use _ or - unless you want to serve them over HTTP.

于 2012-05-05T20:46:32.910 に答える