On 13 Jul 2015, at 12:48 pm, Chris Page <email@hidden> wrote:
2. "screens" and "frame" are properties, not functions, so you shouldn't use "()" with them.
Really?
Here's Steve's code and how it looks logged in ASObjC Explorer:
0000.001 [4] set ss to current application's NSScreen's screens() --> (NSArray) {(NSScreen) <NSScreen: 0x600000865540>, (NSScreen) <NSScreen: 0x60000026e840>} 0000.001 [5] set leftScreenBox to (ss's objectAtIndex:1)'s frame() --> {origin:{x:-2560.0, y:0.0}, size:{width:2560.0, height:1440.0}}
The resulting NSRect is bridged to a record, as at least I would expect.
Here's the code without parens:
0000.002 [6] set ss to current application's NSScreen's screens --> (NSArray) {(NSScreen) <NSScreen: 0x600000865540>, (NSScreen) <NSScreen: 0x60000026e840>} 0000.002 [7] set leftScreenBox to (ss's objectAtIndex:1)'s frame --> (NSConcreteValue) NSRect: {{-2560, 0}, {2560, 1440}}
You end up with an NSValue containing an NSRect, which you then have to unbox. But how do you unbox it? You get the rectValue property of it. But then you run into exactly the same issue:
With parens:
0000.003 [8] set leftScreenBox to leftScreenBox's rectValue() --> {origin:{x:-2560.0, y:0.0}, size:{width:2560.0, height:1440.0}}
Without parens:
0000.003 [8] set leftScreenBox to leftScreenBox's rectValue --> (NSConcreteValue) NSRect: {{-2560, 0}, {2560, 1440}}
This is going to happen with every method that doesn't return an object.
Although it may currently work, it is superfluous and the exact meaning of using parenthesis after a property name may change in the future. (e.g., it should probably mean instead "get the property, whose value is a function, then call that function", just as it does when sending the message to an AppleScript object that has a property whose value is a handler.) You're making me feel very, very nervous...
Last time this issue was discussed here, Chris Nebel weighed in, clarifying that leaving off the parens was equivalent to calling [object valueForKey:propertyname]. But there was no mention of its being the preferred way.
|