Wouldn't it be nice to do a:
int a = [myArray objectAtIndex:0];
and get the object stored in the NSArray sent an -intValue? Yes, we
could invent a new language for this, but I don't think its necessary
in practice and would be quite a waste of time.
Well it's kind of nice except that the compiler can't know that the
objects in the collection implement intValue.
Actually this is no different to
id a;
[a intValue];
The compiler might issue a warning (unlikely in this case) and if you
want to have it more explicit, use a cast to eg 'NSNumber *'.
So that line would have to compile without warnings and possibly throw
an exception when intValue is called on an object that doesn't support
it during run time.
Yup, thats how things are done in Objective-C. We already have such
implicit selectors for @throw, @"abc" etc.
I like Objective-C for how explicit it is compared to C++. You'd
also need to add other implicit type conversion like float, double,
long long, etc.
Yup, we already have all that in NSNumber. With Obj-C its still the
task of the developer to make useful things with the language :-)
And what do you do with:
char *nullTerminatedString = myStringObject;
Send -charValue to myStringObject. Kinda obvious ;-)
otherwise we wouldn't be able to support all possible C signatures.
C String encoding? UTF8?
That doesn't need to be specified in the language and can be
implemented at library level. Just like @"" is implemented in
Foundation, not in the runtime.
That way old code works the same and the compiler can forbid pointer
obfustication to NSString^ pointers.
So you actually have code which obfuscates an object pointer?!
I would love to see things like @3.14f creating an initialized
NSNumber instance though using the same mechanism @"blah" uses.
The only real advantage in using @ is that it may safe cycles due to
the use of static objects (though an optimizer could do that as well
when a constant is used in an object-reference context).
The compiler already has all the information to coerce a "3.14" to an
object. (which can be seen in the error when trying to convert a float
to a pointer)
Anyway, it's been a fascinating debate so far.
All this, I'm right, no I'm right, no its that way, etc is kinda
fascinating ;-)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden