启用/禁用或激活/停用的方法的命名约定
我目前正在开发一个 Objective C 项目,并且有一种启用/禁用的方法,或者换句话说:激活/停用全局 HTTP 代理。我想知道这种方法的最佳命名约定是什么。该方法有一个 BOOL 参数来决定执行哪个操作,即:启用或禁用。这是一个与大多数编程语言相关的风格问题,我决定我会喜欢这个伟大社区在这个问题上的意见,这个问题由于某种原因困扰着我。
这样好吗?有什么更好或更清楚的吗?
-(BOOL) activate:(BOOL) theActivateFlag;
或
-(BOOL) enable:(BOOL) theEnableFlag;
调用 [proxyObj activate:NO] 或 [proxyObj enable:NO] 是否会被理解为停用代理?
谢谢 :)
I'm currently working on an objective c project, and have a method that enables/disables OR in another term: activates/deactivates a global HTTP proxy. I was wondering what is the best naming convention for such a method. The method has a BOOL argument to decide which operation to carry out, ie: enable OR disable. It is a style question which is relevant to most programming languages and i've decided I would love the input of this great community on this matter which is bothering me for some reason.
Is this good ? anything better or clearer ?
-(BOOL) activate:(BOOL) theActivateFlag;
or
-(BOOL) enable:(BOOL) theEnableFlag;
Will calling [proxyObj activate:NO] OR [proxyObj enable:NO] be understood as deactivating the proxy ?
Thx :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Apple 在自己的类中使用
enabled
属性:这将创建以下 getter 和 setter:
或者您可以为您的代理提供一对
activate
和deactivate< /code> 方法或
enable
和disable
方法。Apple makes use of an
enabled
property in their own classes:That creates the following getter and setter:
Or you can give your proxy a pair of
activate
anddeactivate
methods orenable
anddisable
methods.我喜欢 form 在我的代码中反映 function
在文件的顶部我会放置一个
并让我的函数成为
并将其用作
这不是标准方式做事情的过程,但对我来说,它更清晰,并且不需要单独的激活器/去激活器。
I like form to reflect function in my code
At the top of the file I'd put a
and have my function be
and use it as
This isn't the standard way of doing things, but for me it is clearer and eliminates the need for separate activators/deactivators.
我曾想过(经过思考并改变主意几次)...
...会更有意义,尽管我会是第一个承认我偶尔会沉迷其中的人命名约定的暗坑令人绝望(墙上涂满了表达得很糟糕的函数和方法名称),所以也许我不适合回答这个问题。 :-)
I'd have thought (after thinking about it and changing my mind a few times)...
...would make more sense, although I'd be the first to admit that I occasionally wallow in dark pits of naming convention despair (the walls daubed with badly expressed function and method names), so perhaps I'm not best placed to answer this. :-)