Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: type coercion was: AGC was: Re: inner classes not possible, (in objc) right?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: type coercion was: AGC was: Re: inner classes not possible, (in objc) right?



On Apr 4, 2005, at 16:36, Guy English wrote:
Helge Hess <email@hidden> wrote:
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 ;-)

I suppose more realistic is

  - (void)cooerceBaseTypeToAddress:(void *)_cval
    type:(char *)_signature;

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.


NSString *myString; // ref counted
NSString ^myCollectedString;

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 ;-)


Greets,
  Helge
--
http://docs.opengroupware.org/Members/helge/
OpenGroupware.org

_______________________________________________
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


References: 
 >Re: AGC was: Re: inner classes not possible,(in objc) right? (From: Dietmar Planitzer <email@hidden>)
 >Re: AGC was: Re: inner classes not possible,(in objc) right? (From: Marcel Weiher <email@hidden>)
 >Re: AGC was: Re: inner classes not possible,(in objc) right? (From: Dietmar Planitzer <email@hidden>)
 >Re: AGC was: Re: inner classes not possible,(in objc) right? (From: Marcel Weiher <email@hidden>)
 >Re: AGC was: Re: inner classes not possible,(in objc) right? (From: Dietmar Planitzer <email@hidden>)
 >Re: AGC was: Re: inner classes not possible,(in objc) right? (From: Prachi Gauriar <email@hidden>)
 >Re: AGC was: Re: inner classes not possible,(in objc) right? (From: Helge Hess <email@hidden>)
 >Re: AGC was: Re: inner classes not possible,(in objc) right? (From: Marcel Weiher <email@hidden>)
 >Re: type coercion was: AGC was: Re: inner classes not possible, (in objc) right? (From: Helge Hess <email@hidden>)
 >Re: type coercion was: AGC was: Re: inner classes not possible, (in objc) right? (From: Guy English <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.