为什么 C 名称要缩写?

发布于 2024-12-05 01:04:09 字数 292 浏览 1 评论 0原文

为什么有一个名为 strcat 的函数,而不是一个名为 stringConcatenation、或 stringConcatstring_concat 或类似的函数?为什么有 clrscr 函数而不是 clearScreenclear_screen

这是否与过去的源代码大小有关,在超大的软盘上每个字节都值金?或者这是程序员天生的懒惰造成的?这是一个约定吗?

Why there is a function called strcat and not a function called stringConcatenation, or stringConcat or string_concat or something like that? Why there is a clrscr function and not clearScreen or clear_screen?

Does it have something to do with source code size in past days, where every byte was worth gold on overly-sized floppy disks? Or is this fueled by programmers' inherent laziness? Is it a convention?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七禾 2024-12-12 01:04:09

这部分是历史原因。

在非常古老的 C 编译器中,无法保证使用标识符名称的前 8 个字符以上来确定唯一性。这意味着,最初所有标识符都必须是八个或更少的字符,因此方法名称都变得很短。

有关详细信息,请参阅C 书中的标识符

This is partly historical.

In very old C compilers, there was no guarantee that more than the first 8 characters of an identifier name would be used to determine uniqueness. This meant that, originally, all identifiers had to be eight or fewer characters, so method names were all made short.

For details, see Identifiers in the C Book.

七度光 2024-12-12 01:04:09

当 C 及其相关工具最初被开发时,输入设备并不像现代键盘那么容易使用。我从未真正使用过 ASR-33 Teletype,但据我了解,它打字在这样的庞然大物上,stringConcatenation 比键入 strcat 困难得多(如果没有自动完成功能,您将不得不键入没有拼写错误的整个名称)。激活每个键都需要很大的压力。以现代标准来看,产量也慢得令人痛苦。

这也解释了为什么常见的 Unix 命令名称如此简洁(mvcp 而不是 moverename 和 <代码>复制)。

这可能也是旧链接器仅支持此类短名称的原因。程序员通常会首先创建短名称,因此使用稀缺的内存来允许更长的名称没有什么意义。

除此之外,还有一个理由是较短的名字与较长的名字一样好。库函数的名称,无论是 strcat 还是 stringConcatenation(或者是 stringConcatenateString_ConcatenatestringCatenation< /code>?) 本质上是任意的。打字的便捷性不再像以前那么重要,但仍然是一个考虑因素。

When C and its associated tools were first being developed, input devices were not nearly as easy to use as modern keyboards. I've never actually used an ASR-33 Teletype, but as I understand it typing stringConcatenation on such a beast was significantly more difficult than typing strcat (and without autocompletion, you would have had to type the entire name with no typos). It took a substantial amount of pressure to activate each key. Output was also painfully slow by modern standards.

This also explains why common Unix command names are so terse (mv and cp rather than move or rename and copy).

And it's probably also why old linkers only supported such short names. Programmers would generally create short names in the first place, so there was little point in using scarce memory to allow for longer ones.

In addition to all this, there's a case to be made that shorter names are just as good as longer ones. Names of library functions, whether strcat or stringConcatenation (or is it stringConcatenate? String_Concatenate? stringCatenation?) are essentially arbitrary. Ease of typing isn't as important as it once was, but it's still a consideration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文