I have a few makefiles that store shared variables, such as CC=gcc , how should I name them?
The开发者_开发问答 candidates are:
common.mk
Make.common
Makefile.common
.. which is more classic? Is there a standard?
Similarly, I have some shell scripts, which should i choose among the following:
do_this_please.sh
do-this-please.sh
DoThisPlease.sh
doThisPlease.sh
Is there a generally accepted 'case' and suffix for these?
Google's open-source style uses underscores as separators: https://google.github.io/styleguide/shellguide.html#s7.4-source-filenames.
So in your case, it would be do_this_please.sh
or do_this_please
using this style.
What you've got are the bits that glue a build together. Build scripts, auto-generated configs, makefiles that other makefiles include - questioning how that stuff should be named is a good idea.
Most of all, be consistent.
I've seen a lot of .mk extensions for files included via the Makefile. However, as Gyom suggests, it's a very subjective question.
Whatever makes the syntax highlighter in your editor of choice happy is probably a good choice. If you're on a team where everyone uses something different, ask folks. For me, naming a makefile include with a .mk extension highlights correctly for everyone. Naming shell scripts with a .sh suffix helps in a similar way.
In short, make the file names obvious and try to make syntax highlighting work on as many editors / IDEs as possible. Makefile.common might not do that, common.mk may have a better shot.
I would go for do_this_please.sh
. Here is my reasoning:
From a readability perspective, spacing is preferable. This takes us away from the camelcase.
The dash has special meaning in most shells, so pretty-print lexers will pick it up and give odd visualisations when pretty-printing something involving one of your files. You see a case above.
This leaves the underscored version. Some additional points in favour:
- This convention is the same as module names for Python modules (cmp. PEP 8). Modules in python group code together. Your shell script could also be seen as such a grouping.
- Pythonians will have an immediate idea as to how much and what scope of function you offer. Python is very popular, with its home-stay originating in scripting, so its conventions are probably a good template.
Since the purpose of the shell script is to execute command line commands, IMO the naming convention of the shell script should follow the naming conventions for files because it's more related to the operating system rather than a particular programming language. Since most operating systems use -
or _
as word separators, it's better to name the script do-this-please.sh
or do_this_please.sh
. I personally use do_this_please.sh
, because I think it looks better.
I would recommend always adding .sh extension to shell scripts, because if other people are looking through your project, do_this_please
won't give them enough information about the purpose of the file without opening it. On the other hand when they see the extension, they know the file is a shell script and seeing the name of the script, they know the whole purpose of the file without having to open it.
It is quite a subjective question, so I'll answer it with a subjective answer :-)
IMHO, go for Makefile.common
and do-this-please
(with or without .sh
suffix). I've seen these a lot and they are indisputably readable.
精彩评论