5 ms·
Regarding concurrency: [[^ (Foo*) (Foo* bar) { return bar; } copy] autorelease] is a pretty ugly way of writing a lambda. It's like arguing that java can p
by fleitz 15y ago
Regarding concurrency:
[[^ (Foo*) (Foo* bar) { return bar; } copy] autorelease]
is a pretty ugly way of writing a lambda. It's like arguing that java can pass functions via anonymous classes. Yes, technically you can but it's pretty ugly.
Another underlying problem is that the only language that can call Obj-C libraries is Obj-C.
.NET and the JVM solved this problem long ago, I know that Python/Perl/Ruby also have this problem outside of the JVM/CLR.
As far as GC, Obj-C effectively doesn't have it as most Obj-C outside of Apple is written for iOS which doesn't support GC.
You could create a point system and call Obj-C a modern language but working with it feels anything but. Apple doesn't need any serious rewrite, they need to make MacRuby work on the iPhone. That's it.
- ryanpetrich 15y agoAny language can call Objective-C via the runtime. In pure C: void *foo = objc_msgSend(objc_getClass("NSObject"), sel_registerName("alloc"))
- panic 15y agoIn every Objective-C API I've seen that uses blocks, the framework takes care of the "[[... copy] autorelease]" bit. In practice, the code looks something like (to borrow your block with foos and bars): [array transformFoos:^(Foo*) (Foo* bar) { return bar; }]; I'm not sure there is a more succinct way to write a lambda with typed arguments and a typed return value.
- schrototo 15y agoObjective-C can sometimes be pretty verbose, yes, but that's a very contrived block example, especially since it doesn't really relate to concurrency in any way. A more real-world example employing blocks with GCD would be: dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ // do some time-consuming work dispatch_async(dispatch_get_main_queue() ^{ // do stuff on the main thread, like updating UI }); }); That's actually pure C. Typical block usage with Cocoa would be something like: [myArray enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id obj, NSUInteger idx, BOOL *stop) { // do something with obj concurrently }];
- headhuntermdk 15y agoyou forgot a BOOYAH!! at the end of that
- fleitz 15y agoCan you really do the latter in Obj-C? As I understood it you needed to copy and autorelease the block to move it from stack allocation to heap allocation.
- schrototo 15y agoThat's right, but if the receiver needs to have the block on the heap for whatever reason, it's his responsibility to take care of that. Blocks are really no different from any other method argument.
- phatbyte 15y agoI'm with you on MacRuby, the thing is (anyone correct me if I'm wrong), MacRuby is being maintained by Apple with just one developer, at the last time I checked, so MR still feels like a bastard son, which means, no xcode documentation, or auto-suggest, code browsing like we have with OjbC. But I see it as a good alternative for apple development in a near future, let's just hope Apple sees it as well.
- Leynos 15y ago>Another underlying problem is that the only language that can call Obj-C libraries is Obj-C. In practice this is the case, but the Etoile guys have written AppKit applications in Io and Smalltalk, and they have an ObjC -> JavaScript compiler running thanks to LLVM. So given time, I think this statement will come to be eroded away.
- deleted 15y ago[deleted]
- stcredzero 15y agoApple doesn't need any serious rewrite, they need to make MacRuby work on the iPhone. That's it. Lua is already on the iPhone, and will probably give you an order of magnitude performance advantage over Ruby.