为什么 Objective-C 文件使用 .m 扩展名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/652186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:16:31  来源:igfitidea点击:

Why do Objective-C files use the .m extension?

objective-cfile-extension

提问by Kuba Suder

Since I started learning Objective-C and Cocoa, I've been wondering why they have chosen the extension .m for the implementation files - was it supposed to mean something, or was it just a random letter?

自从我开始学习 Objective-C 和 Cocoa 以来,我一直想知道为什么他们为实现文件选择了扩展名 .m - 它应该是什么意思,还是只是一个随机字母?

回答by splattne

Today most people would refer to them as "method files", but

今天大多数人会称它们为“方法文件”,但是

"The .m extension originally stood for "messages" when Objective-C was first introduced, referring to a central feature of Objective-C [...]"

“包括.m的最初代表”essages“时Objective-C的首次引入,参照目标C的核心特征[...]”

(from the book "Learn Objective-C on the Mac" by Mark Dalrymple and Scott Knaster, page 9)

(来自Mark Dalrymple 和 Scott Knaster 的“ Learn Objective-C on the Mac”一书,第 9 页)

EDIT:To satisfy an itch I emailed Brad Cox, the inventor of Objective-C, about the question and he answered with this single line:

编辑:为了满足我的渴望,我给Objective-C 的发明者Brad Cox发了一封电子邮件,关于这个问题,他用这行回答:

"Because .o and .c were taken. Simple as that."

“因为 .o 和 .c 被占用了。就这么简单。”

Here's the email as visual proof:

这是电子邮件作为视觉证明:

Visual Proof

视觉证明

回答by Adam Rosenfield

It stands for "methods". From the comp.lang.objective-C FAQ:

它代表“方法”。来自comp.lang.objective-C 常见问题解答

The organisation of Objective-C source is typically similar to that of C or C++ source code, with declarations and object interfaces going into headerfiles named with a .h extension, and definitions and object implementations going in files named with a .m (short for methods) extension.

Objective-C 源代码的组织通常类似于 C 或 C++ 源代码的组织,声明和对象接口进入以 .h 扩展名命名的文件,定义和对象实现进入以 .m 命名的文件(简称对于方法)扩展名。

回答by baker1990

.m files contain the (m)ethods. Possible reason?

.m 文件包含 (m) 方法。可能的原因?

回答by Martin Kersten

Wild guess: 1983 was ObjectC introduced along with the first Macintosh computer... . So it might be m as in macintosh or m as in methods or even both.

疯狂猜测:1983 年 ObjectC 与第一台 Macintosh 计算机一起推出...... 所以它可能是 m 就像在 macintosh 中一样,也可能是 m 在方法中,甚至两者都是。