Re: Objective-C and it's future
Re: Objective-C and it's future
- Subject: Re: Objective-C and it's future
- From: Thomas Davie <email@hidden>
- Date: Sat, 8 Jul 2006 02:12:36 +0100
On 8 Jul 2006, at 02:00, Gregory Weston wrote:
Thomas Davie wrote:
However, when we are dealing with much more abstract concepts such as
objects, we generally know what our data structures are. We know how
they are going to be used, and we know what they should and should
not do.
But notice what you said there. Or what you didn't. You indicated
that we know and care about _behavior_. Not structure, nor
appearance, nor type. We just want to know that when we send "this
message" we'll get a response that, itself, only needs to conform
to certain behavior. We don't really want collections to be of
certain specific types because there's no reason to restrict a
collection to holding only one type of data. That may not be so
obvious for a traditional integer-index array, but consider an
associative array. I rarely want a dictionary in which _every_ key
is a string and _every_ value is a numeric value.
On the contrary, you just need a good type system. For example, the
constraint that I want all elements in the array to be comparable
would be something akin to asking in (for example) Haskell that all
elements in a list to be sorted must be comparable... This is written
sort :: Ord a => [a] -> [a]
That is - if the type 'a' is orderable (i.e. it responds to functions
about ordering), then the sort function maps lists containing objects
of type a to lists containing objects of type a. If the elements of
the list are not orderable, then sorting cannot be applied.
This constrains us to all elements being the same the same type (as
long as it's orderable), which is not quite what we want, we want,
the objects to be any one of many different types as long as they are
orderable.
So, supposing we want an array containing only NSStrings, we might
invent this syntax:
NSArray[NSString]* foo;
if we want an array of objects that accept comparison methods we
might specify
NSArray([id]<NSComprable>)* foo;
If we want an array where all objects are the same type and all
objects accept comparison methods we might specify
NSArray[id <NSComparable>]* foo;
If we want a truely dynamic array (as we have at the moment we might
write
NSArray[id]* foo;
or even have the normal syntax default to this definition.
Now obviously here I'm inventing syntax and some framework, but this
provides enough power to describe all the situations you want to. So
what's against having this descriptive power in the language when
it's very useful for checking the correctness of the program.
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