5 ms·
The given example for HOM is a bit unfair. From their docs: for ( NSView *aView in [[self view] subviews] ) { [aView setNeedsDisplay]; } They use
by LinaLauneBaer 13y ago
The given example for HOM is a bit unfair. From their docs:
for ( NSView *aView in [[self view] subviews] ) {
[aView setNeedsDisplay];
}
They use this as an example to show that Objective-C is bad. However you can rewrite that with:
[self.view.subviews makeObjectsPerformSelector:@selector(setNeedsDisplay)];
That being said: I think that Objective-C could move faster as a language. We have seen Apple to speed up the development of Objective-C during the last few years and I think that Apple will move even faster in the future.
- mpweiher 13y agoRight, I used an example from real code rather than a made up example. The difference is that makeObjectsPerformSelector: doesn't handle non void returns, only handles limited argument numbers and types (and needs a separate version of the core method for each). #( 1 2 3 4 5 ) collect + 5 This also works with HOM, as does -ifResponds, -async etc.
- fmateoc 13y agoI don't mind trying to come up with less boilerplate syntax, but how does the reader of the code know when something is a HOM or a normal message? The above example is valid syntax in existing Smalltalk, a Smalltalk developer would interpret it as collect returning a value that would be added to 5. I think this ambiguity is much worse than any advantage compactness might bring.
- fmateoc 13y agoJust as an example, writing #( 1 2 3 4 5 ) + 5 would actually be even more compact and more intuitive. A Smalltalk developer would interpret this as #+ being implemented in Collection, and the expectation would be that the implementation of #+ would be something like + arg ^self collect: [:each | each + arg]
- LinaLauneBaer 13y agoObjective.st has a very clean syntax. But this can also be done with Objective-C: [[@[@1, @2, @3] valueForKeyPath:@"@sum.self"] integerValue] + 5 This can be improved: @implementation NSArray (Private) - (NSInteger)collect { return [[self valueForKeyPath:@"@sum.self"] integerValue]; } @end And then you can write: [[@[@1, @2, @3] collect] + 5; I know: HOM is a more abstract/generic thing. If it was built in the language you could just use it as is without reinventing the wheel all the time... I just want to point out that Objective-C can be made look nice as well :)
- mpweiher 13y agoYes, I first implemented HOM in Objective-C, back in 1997 or so... However, collect + 5 doesn't first sum and then add 5 to the sum, it distributes the +5 to every element, and any other message you care to send.
- LinaLauneBaer 13y agoOmg are you marcel weiher? How can I do you something good? Beer? Candy? :) Back in the days I read your paper and obviously I forgot what "collect" means... If you are Marcel then you are one of my heros.
- jimbokun 13y agoHow does this work? Seems like "+ 5" should be a block, but there's no square brackets.
- mpweiher 13y agoHigher Order Messaging: http://en.wikipedia.org/wiki/Higher_order_message http://en.wikipedia.org/wiki/Higher_order_message http://www.metaobject.com/papers/HOM-Presentation.pdf http://www.metaobject.com/papers/HOM-Presentation.pdf http://www.metaobject.com/papers/Higher_Order_Messaging_OOPSLA_2005.pdf http://www.metaobject.com/papers/Higher_Order_Messaging_OOPS...
- jimbokun 13y agoThanks! Those are very clear and thorough explanations.