• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Objective-C and it's future
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C and it's future


  • Subject: Re: Objective-C and it's future
  • From: Andrew Satori <email@hidden>
  • Date: Mon, 10 Jul 2006 10:43:55 -0400

Not to pick nits, but this isn't an issue with Objective C, it's a design choice in the Cocoa class library, and it it really bothers you, use Objective C++ and implement an STL Vector or STL List, but I don't feel that it's really an issue.


No, Cocoa doesn't support what you want with the base class, but nothing prevents you from deriving a class that is Type specific. I don't know how many people on this list have used Borland's Delphi, but this is literally how it deals with this situation.


There is a base class, (TList in Delphi, NSMutableArray in Cocoa) that is a generic array. I deals with pointers to memory and that's it, so that it can take any type of item. That leaves you, the developer with two options. First, you can just use the list and typecast (if you desire) the array elements as you push/pop to/from the array. Second, you take the Delphi type approach and implement type specific lists derived from the base generic list. (TStringList, TMenuItemList, TListViewItems, TControls, etc). Subclass NSMutableArray and then embed your type casting logic into overridden methods. Now the compiler will do your type checking for you.

What's interesting is that what your note appears to be asking, is for C# style Generics (not necessary in Objective C IMO), and C++ style strong typing at the same time. The funny thing is, that Objective C supports variants of both and has for a long time. The 'id' type is little more than a 'void *' in C/C++, and due to the message based designs of Objective C, doesn't require all the internal gyrations of C#'s reflection.emit in order to accomplish the same basic things. At the same time, you can be anal, like I am, and strong type your code. This way I can leverage both worlds, I don't use 'id' very often, because I find comfort in compile time type checking, but it really isn't necessary, which is, in many ways the elegance of Objective C.

Andy


On Jul 7, 2006, at 8:42 PM, Thomas Davie wrote:


On 8 Jul 2006, at 01:41, Shawn Erickson wrote:

On 7/7/06, Rob Ross <email@hidden> wrote:

I'm just learning Obj-C myself, so maybe my understanding is not
correct. But, don't you actually have the option to use static typing
in certain instances, and use dynamic typing in others?


Eg:

id      myStr;

vs

NSString *myStr;

Won't the second version give you the benefits of static typing
(compiler time checking)?

So my understanding is you can have the best of both worlds. Or have
I misunderstood something?

Correct.

That is correct, but can you specify for me an NSArray containing only items that respond to a specific display method?


This is the sort of check that I would like to be able to do at compile time.

Bob
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • [Modertator] Re: Objective-C and it's future
      • From: cocoa-dev-admins <email@hidden>
References: 
 >Objective-C and it's future (From: Thomas Davie <email@hidden>)
 >Re: Objective-C and it's future (From: Charlton Wilbur <email@hidden>)
 >Re: Objective-C and it's future (From: Rob Ross <email@hidden>)
 >Re: Re: Objective-C and it's future (From: "Shawn Erickson" <email@hidden>)
 >Re: Objective-C and it's future (From: Thomas Davie <email@hidden>)

  • Prev by Date: Re: Just 1 entity in a Core Data document?
  • Next by Date: Re: NSDocument with NSMatrix crasher (10.4)
  • Previous by thread: Re: Objective-C and it's future
  • Next by thread: [Modertator] Re: Objective-C and it's future
  • Index(es):
    • Date
    • Thread