Object-C为什么使用.m作为源码的扩展名?

简介: 在百度中苦苦搜寻无果之后,转而把希望寄托到了google,第一条结果就是我想要的答案: Why do Objective C files use the .

在百度中苦苦搜寻无果之后,转而把希望寄托到了google,第一条结果就是我想要的答案:

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? Does anyone know? I couldn't find such information anywhere on Google...

share | improve this question
 
5  
It's for the *em*plementation. –  dreamlax  Mar 16 '09 at 21:36

4 Answers

up vote 119 down vote accepted

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

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

(from the book "Learn Objective-C on the Mac" by Mark Dalrymple and Scott Knaster, page 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:

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

Here's the email as visual prove:

enter image description here

share | improve this answer
 
Nice inquiry, thanks for sharing. –  ybakos  Dec 8 '11 at 16:34
3  
You bothered to email Brad Cox to find out! You awesome, awesome person. –  Purple Blur  Dec 16 '12 at 14:21
3  
Sounds like he was making a joke. If o and c were taken, why m and not any other available letter ? While I think it's a funny reply, I also find it hard to believe it was simply pulled from a hat and he didn't use any logic in choosing m. –  prototypical  Dec 28 '12 at 15:48
1  
I agree he was likely joking, but likely somewhat tongue in cheek. .m likely was for method or messaging, but also only used because .o and .c were already used. –  bigtunacan  Feb 2 at 18:08

From the first Google result (Wikipedia entry) for "objective c" file extension:

The interface only declares the class interface and not the methods themselves; the actual code is written in the implementation. Implementation (method) files normally have the file extension .m.

share | improve this answer
   

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

share | improve this answer
   

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

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

share | improve this answer

目录
相关文章
|
6月前
|
JSON Java 数据格式
Java读取resource目录下的json文件
Java读取resource目录下的json文件
469 0
|
8天前
【下载问题】下载的文件内容显示[object],[object]
摘要:解决下载文件显示[object],[object]的问题,关键在于文件内容处理。原代码`const temp = [res.data]`未对接口返回的数据进行字符串转换。修改为`const temp = [JSON.stringify(res.data)]`,将数据转化为字符串格式,从而正确显示文件内容。
Object源码解析
Object源码解析
54 0
|
XML JSON JavaScript
json转java实体,JSON和XML的区别比较,c#和c++的编译工具, 静态库和动态库的区别
json转java实体,JSON和XML的区别比较,c#和c++的编译工具, 静态库和动态库的区别
230 0
json转java实体,JSON和XML的区别比较,c#和c++的编译工具, 静态库和动态库的区别
|
XML JSON API
PHP中simplexml_load_string解析xml的正确方式
对接我php接口的是安卓客户端,json字符串中在一个元素的时候是对象类型,多个元素的时候是数组类型,安卓客户端解析就失败了。 所以引申出这篇文章,详细测试、记录一下php中解析xml方式和细节
186 0
|
XML 存储 JavaScript
XML格式文件详解及Java解析XML文件内容方法
XML格式文件详解及Java解析XML文件内容方法
Qt .pro文件之defineReplace函数的用法,实现lib文件名自动添加后缀“d“
Qt .pro文件之defineReplace函数的用法,实现lib文件名自动添加后缀“d“
508 0
|
XML 数据格式 移动开发
转载 VC轻松解析XML文件 - CMarkup类的使用方法
VC轻松解析XML文件 - CMarkup类的使用方法http://www.cctry.com/thread-3866-1-1.html VC解析XML文件的工具有很多,CMarkup, tinyXML,还有IBM的,MS的等等。
815 0