[英]Naming conventions for instances and methods
What is the standard way to name an instance: 命名实例的标准方法是什么:
NSString* myString;
or 要么
NSString* my_string;
Similarly, what is the standard way to name a method: 同样,命名方法的标准方法是什么:
(void) getMyName;
or 要么
(void) get_my_name;
camelCase
is the standard. camelCase
是标准的。 Have a look at Apple's Cocoa coding guidelines . 看看苹果的可可编码准则 。
Also getter methods do NOT have the get
keyword in it. 同样,getter方法中没有
get
关键字。 So getMyName
should just be myName
. 所以
getMyName
应该只是myName
。
It depends on the guidelines (1) applied in your product (2) suggested by the language. 这取决于该语言建议的产品(2)中应用的准则(1)。
Many guidelines for C++, Java and other languages suggest camelCase , like getMyName()
, while python suggest lower_case_with_underscores , like get_my_name()
, see PEP 8 . 有关C ++,Java和其他语言的许多指南都建议使用camelCase ,例如
getMyName()
,而python建议使用lower_case_with_underscores ,例如get_my_name()
,请参阅PEP 8 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.