I am doing some maintenance on a program that accepts command line options. There are a single letter options, as well as long options. Currently, the long options have a single preceding hyphen.
Many tools have double hyphens for their long options. Trying to be consistent with what's out there, I looked at some of the GNU tools, and saw that for the long form, there is a mix of single- and double-hyphens. For example, the GCC compiler has --help
, --version
versus -std
, -funroll-loops
.
So I searched for some documentation on the matter and found this GNU document. There, GNU's style recommendation for long options is to begin with two hyphens.
Now, I wonder why GNU tools don't follow these GNU recommendations? I assume that it is a matter of backward compatibility, but is there more to that?
In programs that I write, when changing the options syntax I usually leave the older form functional but undocumented, or at least give a deprecation warning. Is it not possible to do so for the GCC (and other) program(s)?
There are plenty of reasons not to change:
- There are quite literally millions (probably many more?) of configuration scripts and build files that use the existing command line options. Both recent and very old.
- People are used to the current format so most programmers for many years will just use what they already know out of habit.
- Argument parsing code is often complicated and changing it is just another opportunity for introducing bugs.
- The old backward compatibility single hyphen long options would conflict with the new multiple short options combined so backwards compatibility is difficult.
- Insert many more here.
Reasons to change:
- To follow convention that is already not followed by many applications.
In short convention is nice and should ideally be followed for new stuff but often it is not worth changing stuff just for the sake of conformity.
Makefiles and other build scripts are often written (at least partially) compiler agnostic, so the GNU C compiler (and by extension the GNU compiler collection gcc
) will have to stay compatible to other compilers in how they are to be called. Some C compilers surely predate the GNU Program Argument Syntax Conventions. The same goes for other development-related commands like ld
, ar
etc., especially those part of UNIX standards.
'Legacy' syntax in some commands might even be required to comply to some standards. (The C and C++ standards only seem to specify the programming languages, but I could imagine that the UNIX standards also cover command line arguments for certain development tools.)