Live data from Hacker News

Objective-C literals for NSDictionary, NSArray, and NSNumber

cocoaheads.tumblr.com

21–30 of 58 posts

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#21
post #19
post #9

Nice. I wish for ability for function to return multiple values. Is it possible at all?

You can use C99 struct literals: return (struct x){a,b}; Small structs may be passed in registers. http://stackoverflow.com/a/3355560/27009

IIRC passing Obj-C object pointers in C structs is disallowed or discouraged by ARC.

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#22
On one hand, it's nice, and it'll make coding in Obj-C nicer.

On the other hand, it strengthens the coupling between Objective-C the language the Cocoa the framework, and I'm not sure how I feel about that.

I do like it better than the property dot syntax though. (is a simple assignment to a struct member? is it an objc_msgSend of unknown complexity?)

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#24
post #14
post #7

Earlier quoted context omitted.

> but it really is hard to stay up-to-date. Well, you don't really _need_ to; this one is just syntactic sugar, and the others, while nice (or mostly; I'm unconvinced about ARC), are not necessary. I'd prefer to have the options.

ARC is not really 'needed' for anything, it's just a very nice way to prevent memory leaks and pruning lots of retain/release statements from your code. I would not re-factor existing code without ARC if it was properly debugged for memory leaks and working perfectly, but for all new projects I have it enabled.

Sorry, I meant that I'm unconvinced ARC is nice, not that I'm unconvinced it's not necessary; it clearly isn't.

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#25
post #22

On one hand, it's nice, and it'll make coding in Obj-C nicer. On the other hand, it strengthens the coupling between Objective-C the language the Cocoa the framework, and I'm not sure how I feel about that. I do like it better than the property dot syntax though. (is a simple assignment to a struct member? is it an objc_msgSend of unknown complexity?)

Apple's weird in the way they couple things in different ways than the rest of the industry and against the conventional wisdom. Since essentially nobody has an investment in Objective-C-without-Cocoa or Cocoa-without-Objective-C, I don't see any problem with them evolving them together whichever way seems best to them.

Also, there's long precedent with @"…" syntax for embedding NSString literals and most of the changes are really just preprocessor/static analysis-driven syntactic sugar — sometimes extreme sugar, yes, but optional, highly-predictable, purely-syntactic-cleanup nonetheless. So if they ever decide "the future of Cocoa is Ruby!" or something like that, I'd think most of the sugar could be, to mix metaphors, transplanted.

On that note, though: I don't see Apple moving primarily away from Objective-C any sooner than I see .Net moving primarily away from C#. It's "the language" until something huge changes the landscape, in large part because they've been able to so substantially evolve it, just like Microsoft, who also controls the primary framework used with their language, has been able to do with C#.

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#26

The excessively verbose collection syntax is my #1 pain point with Obj-C. Looking forward to kicking the tires on this one.

It's never before fully struck me how cleanly the "Objective-C is too verbose" complaint really breaks down to two separate issues: one of them being that method names are long (which is arguably a plus) and the other being mostly comprised of the stuff that's apparently mostly taken care of with this release. Actually, I suppose there used to be a third, too: (auto)release/retain statements all over the place.

As somebody who loves the long method names but of course wants less syntactic cruft, I'm really happy with their recent progress.

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#27
post #13
post #2

This is for Apple LLVM 4.0 which ships with XCode 4.4. Also included: - Automatic @synthesize - NSArray/NSDictionary subscripting, eg id object=MyArray[12];

For those wondering: Xcode 4.3 is what currently ships, 4.4 Developer Preview ships with the Mountain Lion per-release, so it only is available to those in Apple's Developer Program.

That is correct. I installed Mountain Lion developer pre-release and Xcode 4.4 this week. BTW, I like Mountain Lion: I have it on my "work" laptop; seems solid.

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#28
post #13

Earlier quoted context omitted.

For those wondering: Xcode 4.3 is what currently ships, 4.4 Developer Preview ships with the Mountain Lion per-release, so it only is available to those in Apple's Developer Program.

> ...so it only is available to those in Apple's Developer Program. correction: Apple's Mac developer program. I'm an iOS developer and I don't see Xcode 4.4 in my dashboard.

This is the second time (to my knowledge, may have been going on for a while) that an Xcode beta has been made available to only one of the two (Mac and iOS) developer programs. The Xcode 4.3 beta was only available to iOS developers -- despite containing bug fixes and improvements useful to developers on both platforms. Now the Xcode 4.4 beta is only available to Mac developers.

I really don't see the logic in withholding from paying members of either platform.

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#29
I'm glad to see these additions, but the syntax for an NSArray literal bugs me.

When I want an array literal in C, I'd write ...

  int foo[] = { 1, 2, 3, 4, 5};
... but in Objective-C, for an NSArray literal I'd write ...

  NSArray *bar = @[o1, o2, o3];
Why did they choose '[' over '{'? Oddly enough, NSDictionary uses '{'.

I feel like the syntax for an NSString literal is more natural (as a C developer).

  NSString *baz = @"look, an NSString literal";
  char szBaz[] = "look, a C string literal";

Re: Objective-C literals for NSDictionary, NSArray, and NSNumber

#30

Well, I guess that was long overdue. Anyway, another nice step to bring Objective-C forward. It seems to develop into a nice combination of low-level, high-performance C and a pretty straightforward, dynamic, object system. In short, I vastly prefer its object system to C++, because it reasonably trades some performance for greater dynamisms and an easier syntax. It'll be interesting how Objective-C will develop.

I completely agree, it's great to see that the language continues to move forward and advance in it's OO design. It's especially nice that these forward steps do not hinder or reduce Obj-C's low-level functionality, leaving available the performance gains from it's use.
Post reply on HN