文档学习:Coding Guidelines for Cocoa

文档学习:Coding Guidelines for Cocoa,第1张

概述  主要讲述编码规范。注意,函数名、类名、常量名的编写规范。 文档地址:http://www.apple.com.cn/developer/mac/library/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html#/apple_ref/doc/uid/10000146 命名   1. It is good t

  主要讲述编码规范。注意,函数名、类名、常量名的编写规范。

文档地址:http://www.apple.com.cn/developer/mac/library/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html#/apple_ref/doc/uid/10000146

命名

  1. It is good to be both clear and brIEf as possible,but clarity shouldn’t suffer because of brevity:

  示例:

   insertObject: atIndex: good
insert:at: not clear; what is being inserted? what does “at” signify

2. 少用缩写,In general,don’t abbreviate names of things. Spell them out,even if they’re long:,但是一些常用的简写是可用的,比如:alloc,temp等等

destinationSelection good
destSel not clea

3. 避免歧义,AvoID ambiguity in API names,such as method names that Could be interpreted in more than one way.

sendPort Does it send the port or return it?
displayname Does it display a name or return the receiver’s Title in the user interface?

4. 一致性,同样功能的函数或接口定义通用可实现多态性的名字

5. 前缀名,比如:NS,UI等等。Use prefixes when naming classes,protocols,functions,constants,and typedef structures. Do not use prefixes when naming methods; methods exist in a name space created by the class that defines them. Also,don’t use prefixes for naming the fIElds of a structure

排布

1. 写一个组合名字时,不要用符号(_、-等等)来分隔不同的单词。应该为单词首字母大写,然后拼在一起。

For method names,start with a lowercase letter and cAPItalize the first letter of embedded words.Don’t use prefixes.
fileExistsAtPath:isDirectory:

For names of functions and constants,use the same prefix as for related classes and cAPItalize the first letter of embedded words.
NSRunAlertPanel
NSCellDisabled

2. 不要用“_”前缀表示私有的方式命名,尤其是对于方法。

因为Apple底层实现使用了这种方式处理隐藏的成员,当你这样用的时候很可能会屏蔽底层实现中的名字,造成不应出现的问题。:Apple reservesthe use of this convention. Use by third partIEs Could result in name-space collisions; they might unwittingly overrIDe an existing private method with one of their own,with disastrous consequences. See "Private Methods" (page 18) for suggestions on conventions to follow for private API.

总结

以上是内存溢出为你收集整理的文档学习:Coding Guidelines for Cocoa全部内容,希望文章能够帮你解决文档学习:Coding Guidelines for Cocoa所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1061310.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存