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

目录
相关文章
|
JavaScript 前端开发 应用服务中间件
【前端项目笔记】原生js上传文件及文件转换成base64、blob类型
项目中经常会用到上传图片上传视频等功能,由于后端nginx限制,经常要进行文件转化才能上传,大文件可能还要进行切片上传处理。
683 1
|
6月前
|
数据格式 Python
【Python】已解决:Excel无法打开文件test.xIsx“,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。
【Python】已解决:Excel无法打开文件test.xIsx“,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。
442 0
|
8月前
【下载问题】下载的文件内容显示[object],[object]
摘要:解决下载文件显示[object],[object]的问题,关键在于文件内容处理。原代码`const temp = [res.data]`未对接口返回的数据进行字符串转换。修改为`const temp = [JSON.stringify(res.data)]`,将数据转化为字符串格式,从而正确显示文件内容。
752 3
|
8月前
|
存储 C语言 C++
C++遍历文件夹获取各文件名称并筛选指定格式类型的文件或具有特定名称的文件
C++遍历文件夹获取各文件名称并筛选指定格式类型的文件或具有特定名称的文件
142 1
|
8月前
|
JSON 前端开发 JavaScript
JS前端读取本地上传的File文件对象内容(包括Base64、text、JSON、Blob、ArrayBuffer等类型文件)
JS前端读取本地上传的File文件对象内容(包括Base64、text、JSON、Blob、ArrayBuffer等类型文件)
kaggle如何解压文件(包含7z类型文件和zip类型文件)
kaggle如何解压文件(包含7z类型文件和zip类型文件)
Object源码解析
Object源码解析
78 0
|
存储 Java 对象存储
用Java批量替换MD文件中的图片地址
用Java批量替换MD文件中的图片地址
用Java批量替换MD文件中的图片地址
File类详解(获取文件名称、大小、路径、创建等)
File类详解(获取文件名称、大小、路径、创建等)
1212 1