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

来源:互联网 发布:北京阿里云备案拍照 编辑:程序博客网 时间:2024/05/16 03:39

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

Why do Objective C files use the .m extension?

up vote53down votefavorite
7

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

activeoldestvotes
up vote119down voteaccepted

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
up vote6down vote

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
  
up vote2down vote

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

share|improve this answer
  
up vote2down vote

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

原创粉丝点击