Will I be okay not using the dot/arrow operators?


#1

Hi,

I have a background in C programming and my goal is to become a very competent iOS developer. I have read Objective-C Programming (BNR) and Programming in Objective-C (by SK) two times each from cover to cover and feel that I have a solid foundation in objective-c as a result. I have no experience with iOS yet and before I move on to iOS Programming (BNR) and some other books on iOS, I would appreciate some clarification on one thing:

Given @property AnotherClass *iVar;
where x is an instance variable of AnotherClass

- (void)aMethod:(AnotherClass *)arg
{
    self->_iVar.x += arg.x;
}

vs.

- (void)aMethod:(AnotherClass *)arg
{
    [[self iVar] setX:[[self iVar] x] + [arg x]];
}

I find the second approach to not only be more consistent within the language but also a little easier to understand and maintain down the road. Looking around the foundation framework a bit, I see a few methods that return plain C structs and I imagine that things can get pretty confusing if a code base has a lot of structs and property accessors both using the dot operator.

Will I be okay if I reserve the dot/arrow operators for use only when dealing with C structs or will I run into any problems when I get into iOS development?

Thanks in advance!!
-john


#2

Dot notation is just syntactic sugar. However, I feel that it just makes the language more confusing.
The important thing is to be consistent when using them, especially when working together with other programmers.
I personally prefer invoking methods to get/set values of properties. You will be okay either way; the compiler doesn’t care, but it is better to be consistent.


#3

I just started digging into iOS Programming (BNR) and I see that the authors also prefer to use messaging vs dot notation so I assume that I will not run into any problems using it throughout iOS development.

Thanks for your response.