为什么GCC(和其他工具)不遵循GNU命令选项约定准则? [英] Why does (do) GCC (and other tools) not follow the GNU command options convention guidelines?

查看:145
本文介绍了为什么GCC(和其他工具)不遵循GNU命令选项约定准则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对接受命令行选项的程序进行一些维护。有单字母选项和长选项。当前,长选项有一个连字符。



许多工具的长选项都有两个连字符。为了与现有格式保持一致,我查看了一些GNU工具,并发现长格式中混合了单连字符和双连字符。例如,GCC编译器具有-help -version -std -funroll-loops



所以我搜索了有关此问题的一些文档,找到此GNU文档。在那里,GNU对于长选项的样式建议是从两个连字符开始。



现在,我想知道为什么GNU工具不遵循这些GNU建议吗?我认为这是一个向后兼容的问题,但是还有什么呢?



在我编写的程序中,更改选项时语法我通常会保留较旧的表单功能,但未记录文档,或者至少给出弃用警告。

解决方案

有很多原因导致无法这样做?

解决方案

更改:




  • 实际上有数百万个(可能还有更多?)配置脚本和使用现有命令行选项的构建文件。

  • 人们习惯于当前的格式,因此许多程序员多年以来都会习惯使用他们已经知道的内容。

  • 参数解析代码通常很复杂,并且更改它只是引入错误的另一个机会。

  • 旧的向后兼容单连字符长选项将与新的多个短选项组合在一起,因此向后兼容很难。

  • 在这里插入更多内容。



更改原因:




  • 要遵循许多应用程序尚未遵循的约定。



简而言之,约定是不错的做法,理想情况下,应该对新内容进行遵循,但通常仅出于一致性考虑,不值得更改内容。


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.

这篇关于为什么GCC(和其他工具)不遵循GNU命令选项约定准则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆