您的位置:首页 > 移动开发 > Objective-C

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

2013-05-17 16:47 645 查看
在百度中苦苦搜寻无果之后,转而把希望寄托到了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...

objective-c file-extension
share|improve
this question
edited Jan 17 at 20:27

asked Mar 16 '09 at 21:17




Psionides

1,56331725

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:



share|improve
this answer
edited Feb 21 '11 at
13:54

answered Mar 16 '09 at 21:46




splattne

36.3k24128192

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
answered Mar 16 '09 at 21:24




ssg

14.9k83874

up
vote2down
vote
.m files contain the (m)ethods. Possible reason?

share|improve
this answer
answered Mar 16 '09 at 21:25





baker1990

3613

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
answered Mar 16 '09 at 22:03




Adam Rosenfield

132k20212320

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: