点标记与声明属性的消息符号 [英] Dot notation vs. message notation for declared properties

查看:92
本文介绍了点标记与声明属性的消息符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们现在有属性的点符号。我看到过各种返回关于点符号与消息符号的优点。为了保持响应不受影响,我不会在问题中回答任何一种方式。

We now have the "dot" notation for properties. I've seen various back and forths about the merits of dot notation vs. message notation. To keep the responses untainted I'm not going to respond either way in the question.

你对点符号和消息符号的访问属性有什么想法?

What is your thought about dot notation vs. message notation for property accessing?

请尝试保持它的焦点Objective-C - 我的一个偏见我会提出的是Objective-C是Objective-C,所以你的偏好,例如Java或JavaScript无效。

Please try to keep it focused on Objective-C - my one bias I'll put forth is that Objective-C is Objective-C, so your preference that it be like Java or JavaScript aren't valid.

有效的注释是与技术问题(操作顺序,强制转换,性能等),清晰度

Valid commentary is to do with technical issues (operation ordering, cast precedence, performance, etc), clarity (structure vs. object nature, both pro and con!), succinctness, etc.

注意,我是一个严谨的质量和可读性的学校,在代码中工作的巨大的项目,其中代码约定和质量至关重要(写一次读一千次范例)。

Note, I'm of the school of rigorous quality and readability in code having worked on huge projects where code convention and quality is paramount (the write once read a thousand times paradigm).

推荐答案

不要使用点的行为。使用点来访问或设置属性,如东西,通常属性声明为属性。

Do not use dot for behavior. Use dot to access or set attribute like stuff, typically attributes declared as properties.

x = foo.name; // good
foo.age = 42; // good

y = x.retain; // bad

k.release; // compiler should warn, but some don't. Oops.

v.lockFocusIfCanDraw; /// ooh... no. bad bad bad

对于Objective-C的新手,我建议不要使用东西声明为@property。

For folks new to Objective-C, I would recommend not using the dot for anything but stuff declared as @property. Once you have a feel for the language, do what feels right.

例如,我发现以下是完全自然的:

For example, I find the following perfectly natural:

k = anArray.count;
for (NSView *v in myView.subviews) { ... };

您可以期望clang静态分析器将增加能力,仅用于某些模式或不用于某些其他模式。

You can expect that the clang static analyzer will grow the ability to allow you to check that the dot is being used only for certain patterns or not for certain other patterns.

这篇关于点标记与声明属性的消息符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆