Using the dot syntax is not coding style or a matter of taste!
The dot syntax is for accessing properties. The message sending syntax is for dispatching methods. They are conceptually two different things. Legacy and backwards compatibility to Objective-C 1.0 unfortunately makes them interchangeable, which has caused allot of confusion.
Weather to user the dot-syntax or not is dead simple:
- If a public header declares something as property, then access it as a property using the dot-syntax, as the author of the interface explicitly intended!
- If a public header declares something as a method, then access it using the message sending syntax, as the author of the interface explicitly intended!
- Make NO exceptions.
The hard question is, should you declare something as a property, and thus tell your clients that doit-syntax should be used, or should you declare a method? The simple answer is:
- Use properties for states (is something).
- Use methods for behaviors (do/calculate something).
Another rule of thumb is that properties should be self-contained, there should be no other way to change the value of the property but to set the property itself. This is Not a hard rule, use common sense, many sensible exceptions exist. For example a hidden
property that can be changed with setHidden:animated:
method.