开发者

Not Using Dot Notation for Properties?

One of the books that I reference rejects dot-notation for properties in Objective-C 2.0. I开发者_StackOverflow社区s this a common mindset?

Note: This is an empirical, programming-related question regarding the popularity of a syntactic tendency. Obviously, the most useless answers are personal -- "Well, I don't use it," -- and the more interesting ones come from a larger universe of observations. If anybody has any actual statistics on the matter, that's even better.


If you look at the code people post on Stack Overflow and Apple's sample code, you'll see that dot notation is very commonly used. Some people prefer the normal message-sending syntax for philosophical reasons, but it's generally taught with dot-notation these days, so it's not unreasonable to assume that's what most people use.

The most popular and prominent example of "anti-dot" sentiment is Joe Conway's post on the Big Nerd Ranch blog. The Big Nerd Ranch guys are very venerable Cocoa programmers, so people tend to take their opinions seriously.


No, it's not a common mindset. If you look at the sample code people posted here, you'll see that the majority of people are using it.

My personal opinion is that it was a mistake to invent it. It confuses beginners into thinking that property access is somehow different from normal message passing. Having said that, there are occasions where it makes code clearer to read.


I don't use it, because it only works if I define the type of the object. Often, my objects are of type id, and that doesn't allow me to use the dot syntax. So, because I don't want to have to bother to check what kind of type I declared my object as, I just don't use it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜