为什么 C 名称要缩写?
为什么有一个名为 strcat
的函数,而不是一个名为 stringConcatenation
、或 stringConcat
或 string_concat
或类似的函数?为什么有 clrscr
函数而不是 clearScreen
或 clear_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这部分是历史原因。
在非常古老的 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.
当 C 及其相关工具最初被开发时,输入设备并不像现代键盘那么容易使用。我从未真正使用过 ASR-33 Teletype,但据我了解,它打字在这样的庞然大物上,
stringConcatenation
比键入strcat
困难得多(如果没有自动完成功能,您将不得不键入没有拼写错误的整个名称)。激活每个键都需要很大的压力。以现代标准来看,产量也慢得令人痛苦。这也解释了为什么常见的 Unix 命令名称如此简洁(
mv
和cp
而不是move
或rename
和 <代码>复制)。这可能也是旧链接器仅支持此类短名称的原因。程序员通常会首先创建短名称,因此使用稀缺的内存来允许更长的名称没有什么意义。
除此之外,还有一个理由是较短的名字与较长的名字一样好。库函数的名称,无论是
strcat
还是stringConcatenation
(或者是stringConcatenate
?String_Concatenate
?stringCatenation< /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 typingstrcat
(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
andcp
rather thanmove
orrename
andcopy
).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
orstringConcatenation
(or is itstringConcatenate
?String_Concatenate
?stringCatenation
?) are essentially arbitrary. Ease of typing isn't as important as it once was, but it's still a consideration.