tags:

views:

73

answers:

3

One of the books that I reference rejects dot-notation for properties in Objective-C 2.0. Is 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.

+2  A: 

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.

Chuck
Thanks for the perspective, Chuck. Regardless of its technical merits, popularity is important too.
Yar
Sometimes the venerable get stuck in their ways....
bbum
+1  A: 

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.

chpwn
you mean the compiler or XCode as you're writing code?
Yar
I mean the compiler.
chpwn
But it's "just" a warning, right? And there's no way to suppress that warning (if you wanted)?
Yar
No, it's an error.
chpwn
+1  A: 

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.

JeremyP
I just don't understand why it could be different than normal message passing. This is NOT part of my question, but what exactly would a beginner understand incorrectly?
Yar
Dot notation looks like normal C struct member access. Beginners often get confused into believing it *is* the same as C struct member access.
JeremyP