简体   繁体   English

密集使用GCD的命名约定

[英]Naming conventions for using GCD intensively

I just dived into the world of using dispatch_queue a little bit more intensively and was wondering if there are some naming conventions that should be used just for GCD objects, so that the code of the classes is then more easily divided into GCD and other Code . 我只是潜入了一个更密集地使用dispatch_queue的世界,并想知道是否有一些应该只用于GCD对象的命名约定 ,这样类的代码就更容易分成 GCD其他代码 Or could it be that it is a bad idea to have separate naming conventions for GCD? 或者可能是为GCD设置单独的命名约定是一个坏主意?

I'd suggest to simply stick to the usual Cocoa and CoreFoundation naming conventions. 我建议简单地坚持通常的CocoaCoreFoundation命名约定。 Extend them as needed. 根据需要扩展它们。

Edit after comments: 评论后编辑:

First of all, you shouldn't start variables with an underscore as this is reserved for Apple. 首先,您不应该使用下划线启动变量,因为这是为Apple保留的。 Instead, I recommend to postfix with underscore, like someVariable_ or prefix with something else (for example, a colleague of mine uses i_ for instance variables and g_ for globals). 相反,我建议使用下划线的postfix,比如someVariable_或者其他东西的前缀(例如,我的同事使用i_作为实例变量, g_作为globals)。

Whether you want to add some kind of polish notation (like prefixing with q_ for queues) is entirely up to you, it's a matter of taste. 是否要添加某种波兰表示法(如q_为队列添加前缀)完全取决于您,这是一个品味问题。 I think it's more important that you can recognize what a variable is used for, like imageProcessingQueue_ instead of just queue_ . 我认为你能认识什么是变量用于,喜欢它的更重要的imageProcessingQueue_而不是仅仅queue_

The problem is that this is entirely subjective and cannot be answered in an "this is the ultimate truth" way. 问题在于,这完全是主观的,无法以“这是最终真理”的方式回答。 Common sense and forethought are important and laziness (abbreviated names or very generic terms like simply queue_ ) should be avoided. 常识和预见是重要的,应该避免懒惰(缩写名称或非常通用的术语,如简单的queue_ )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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