简体   繁体   English

实例和方法的命名约定

[英]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

虽然我还建议使用jtbandes提供的链接,但本文可能会帮助您理解以及如何编写。 可可指南具有很好的定义以及可以快速浏览的漂亮示例。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM