views:

86

answers:

2

I am trying to write the following without using dot notation ...

[scrollView setMinimumZoomScale: scrollView.bounds.size.width / image.size.width];

Is this right?

[scrollView setMinimumZoomScale: [scrollView bounds].size.width / [image size].width];

cheers Gary.

+5  A: 

There actually is something wrong with dot notation. It can get really ugly and hard to read in objective-c. While you'll get differing opinions and flame wars (which I probably just started), I'll be glad to share with you my rule of thumb. Use dot notation for structs. Use brackets for everything else. Read Joe Conway's (of Big Nerd Ranch) blog post on the subject.

Money quote from Joe:

It is my belief, after teaching roughly 300 students Objective-C, that dot-notation is confusing. It hinders the main goal of software development: writing maintainable, effective, efficient, easy to read and bug-free code.

In answer to your question, YES! Looks perfect. You're accessing a struct with your dots.

Stick to your guns on the dot notation. Don't let anyone bully you into using them. ;-)

-Matt

Matt Long
"It is my belief, after reading roughly 300 StackOverflow posts on Objective-C, that dot-notation is confusing."
kubi
Thank you Matt, I became aware of the controversy surrounding dot notation when I stared learning objective-c (about 6 months ago), so to simplify my learning I decided to stick with the original bracket notation. Now I prefer it and always use it, I will read Joes blog as a point of reference, much appreciated.
fuzzygoat
in this situation its easy to see whats object and whats struct [scrollView bounds].size.width if you went with dot notation you could easily be led to believe you were accessing all objects.
fuzzygoat
Sorry, but the BNR guys are wrong on this account. Dot notation gives the developer a clear difference between property access and sending a message. Granted sometimes they can be the same, but there are often objects who have properties with no methods. Further abstracting how the object sets its value is a good thing.
jshier
@jshier using dot notation and sending a message are *always* the same. If an object has properties you can access those properties using standard bracket methods. This is exactly the sort of confusion that dot.notation leads to.
kubi
Not that I'm anti-dot.notation. I use it 100% of the time to access properties. I'm just agreeing with @matt and Joe Conway and everyone else that asserts that dot.notation leads to needless confusion.
kubi
@jshier this is *exactly* why dot notation is wrong. It's led you to believe that there is a difference between property access and sending a message. There isn't.
JeremyP
@kubi, @JeremyP: I was mostly trying to restate what I read here: http://cocoawithlove.com/2008/08/in-defense-of-objective-c-20-properties.html
jshier
@JeremyP He was referring to the intent displayed in the source code. In fact, dot-notation can be more informative than brackets because it designates between behavioral methods and property getters.
Preston
A: 

What allows dot-notation to be used (or forbidden)? @property and @synthesize statements?

Gloria
Meltemi
You can use dot notation for any method of the form `-(sometype) method;` You can use also use dot notation to assigm properties if you have a method of the form `(void) setMethod: (sometype) value;`
JeremyP