last day (17 days later) » 

13:16
0
A: Is it ok to use property syntax for no-args methods?

EmptyStackThe first and foremost reason to avoid this type of Dot Syntax usage is that it is strongly discouraged by Apple itself, and may lead to crash or undesired result if used wrongly. Read through the section "Incorrect Use of Dot Syntax" in "Dot Syntax"(from Apple's Doc). There listed the different...

Yes, but I don't see how that applies here? responseString is an accessor method for a (conceptual) string property calculated on the fly with no side-effects.
Who is the down voter?
@Martin Wickman, I think you don't understand the doc. You example and doc example are similar.
@Martin Wickman, responseString is a method like lockFocusIfCanDraw in Doc, no matter you call it as conceptual accessor method or whatever you like.
@Martin Wickman, What do you mean by a conceptual string property?
responseString fits the mental concept of a property (like color of a car), except it's not generated with @property. lockFocusIfCanDraw, otoh, is not a property in any sense. It is a method with with side effects (a verb btw) and the returned boolean is the result from that action, not the value of the "property". That is the difference and also my interpretation of the docs: "don't treat methods like lockFocusIfCanDraw as properties, because it is not a property in any sense". So I think your answer is wrong.
If the guideline was stated simply as "Only use dot-notation when accessing methods that are generated from @property", then I'd agree with you.
You can't code mental concepts in programming languages. You still don't understand what a method is. Even though your method contains single line like return someOtherProperty;, that is a method. If you create declared properties, compiler will create getter and setter methods for the property. Both getters and setters are methods only.
Accessing a property using dot syntax will invoke the getter/setter methods only. So the doc says that properties are allowed to access their getter/setters using dot syntax and not to use the dot syntax to call normal methods(not a getter or setter).
For the record, I've been a developer for 15+ years and I am well aware of what methods is.
I say again. If the case was "only use dot-notation for @property generated methods" then I'd agree. But that is not the case. If it were, then apple surely would have said that.
13:22
But Apple says that "It is strongly discouraged to use dot syntax to call methods".
No they don't, or at least when I search the document it doesn't show up.
Apple allowed dot syntax to access properties to make them behave as normal variables
Didn't you do through these lines, "Incorrect Use of Dot Syntax

The code patterns that follow are strongly discouraged because they do not conform to the intended use of dot syntax, namely for invoking an accessor method."
They "strongly discourage" using properties in any of the four cases they present. None of which is my example.
So, responseString is an property.
Indeed it is
Except not a @property
13:26
How could it be?
I am afraid ;-)
Do you agree that "color" is a property of "car" ?
Objective-C treats a property as a property only if is declared as @property.
Yes. Literally speaking.
My point is that if I create it using @property(...) color or as - (UIColor) color. The resulting code is the same. And it is possible to access with dot-syntax.
It is, as you probably know, possible to do @property(getter=theColor) and then define theColor manually. Or for that matter, just implement - (UIColor) color and override the default generation.
If you don't declare it as a @property, -(UIColor)color would be just an normal method(Not a getter of a property).
Ah, and here is the burning point I think :)
And, yes, from the source code's point of view, it is not a property. Agreed.
But there is no difference in the actual, generated code.
13:33
While you declare @property(getter=theColor), then you are explicitly telling the compiler that the getter is theColor not just color.
If apple figured you should only call @property-generated methods with dot-syntax, they would have said so clearly: "thou shalt not call non-generated methods with dot-syntax"
They don't say that. They say: "don't treat weird methods that has weird side effects as properties"
We can both agree that lockFocusIfCanDraw is not a property. Nor is retain.
Not only because of side effects, its generally not advised to use dot syntax to access non getter/setter methods.
Yes. Its not a property.
Yes, of course. But responseString is getter.
;-)
You sure you are not joking!
No, why do you think I do?
Seriously: If @property() NSString *responseString generates a method -(NSString*)responseString which is considered a getter. If I instead manually create it and it results is the exact same code as the generated one, then it is just a good as the other one.
Byte for byte is it the same. No compiler warning. No errors. No (imo) conflict with guidelines. etc. The same
 
6 hours later…
20:08
I have to side with Martin. A property conceptually speaking is an attribute of an object. My car has a property called colour (I'm English) which is set to "blue". Properties are modelled in Objective-C with a pair of accessor methods, one to get and one to set the value. In Objective C 1.0, that is where it ended.
In Objecive-C 2.0, Apple added dot notation and the @property keyword. All these things do is make it more explicit that the property is a property. You don't have to use them, and IMHO, you shouldn't use the dot notation because the one thing the dot notation is not for, is to make the property behave as a normal variable. It is not and you'll get in trouble if you think it is (this is the main reason I dislike dot syntax)..
20:40
I agree with Jeremy and Martin. Apple's documentation clearly states that the purpose of dot notation is "to invoke accessor methods." It's noted as being particularly useful in conjunction with declared properties, but that's as far as it goes. If Apple had only wanted it to work with declared properties, they would have written that into the compiler — the implementation would probably actually be simpler that way. They chose not to.
The examples of "incorrect use" are, in order: 1) A side-effecting method; 2) A method that doesn't follow the normal setter pattern being used as a setter; and 3) Ignoring compiler warnings on a declared property.

  last day (17 days later) »