Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Draft Proposal for Namespaces in Objective-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Draft Proposal for Namespaces in Objective-C



On 10 April 2012 17:45, Michael Ash <email@hidden> wrote:
>
> There are other, good languages that have both namespaces and dynamic dispatch. Ruby is one example that comes to mind off the top of my head.

To my mind there are two issues we're trying to deal with:

1. namespaces for classes, functions, variables and other standard types.
2. namespaces for selectors.

I can see how 1. would be a useful addition to the language. I'm very
unsure that the trade-offs involved in 2. (increased complexity, at
least in the current proposal) are worth it. Dynamic dispatch as it is
currently implemented is the very heart and soul of Objective-C (and
Smalltalk) and I'm against any proposal which moves method resolution
to compile time (let's ignore properties for now). If it walks like a
duck...

At the very least I'd want to restrict selector resolution to a
runtime method (e.g. objc_namespaceResolveSelector(...)) rather than
the currently proposed @selector changes.

I'm also wondering why no one has suggested the obvious (to me) idea
of treating namespaces as first-class objects as we do for Class.
Objective-C is all about objects after all. So for example to obtain a
Class from a namespace just send a message to the namespace as we now
do to allocate a class, e.g.

Class aClass = [default NSObject]
and
id foo = [[[Namespace Foo] alloc] init];

This seems so much more natural to me than @class() or the dot syntax
and requires no new syntax (other than @namespace and @using) or
further operator overloading. Namespaces could even support properties
(c.f. python) and there would be no ambiguity using the dot operator
for property access (or in structs).

For similar reasons I'd also be in favour of spaces when writing declarations:

// .h
@namespace com.OliveToast

@interface CoolView : UIKit UIView <UIActionSheetDelegate>
...
@end
@end

// .m
// Variable declaration
com.OliveToast CoolView *coolView = [[[com.OliveToast CoolView] alloc] init];

Regards,

John

------------------------
Dr. John Buckley

Olive Toast Software Ltd
www.olivetoast.com
------------------------



On 10 April 2012 17:45, Michael Ash <email@hidden> wrote:
> On Apr 10, 2012, at 12:01 PM, Jean-Daniel Dupas wrote:
>
>>> Plenty of other languages do namespaces without much complexity at all, let alone the mind-numbing kind.
>>
>> They don't have to deal with dynamic message dispatching.
>> Having to specify the namespace to call a method is not something usual AFAIK.
>
> There are other, good languages that have both namespaces and dynamic dispatch. Ruby is one example that comes to mind off the top of my head.
>
> If having to specify the namespace to call a method is unusual, then perhaps that's not the correct approach. But it seems clear enough that Objective-C can have namespaces without adding a huge amount of complexity, since other languages *with similar capabilities* do it just fine. Instead of rejecting the idea out of hand, let's look at how these other languages do it and see what good ideas they have that we can borrow.
>
> Mike
>  _______________________________________________
> 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

 _______________________________________________
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: 
 >Draft Proposal for Namespaces in Objective-C (From: Kyle Sluder <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Kyle Sluder <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Kyle Sluder <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Jonathan Schleifer <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Kyle Sluder <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Jens Ayton <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Uli Kusterer <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Ian Joyner <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Michael Ash <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Jayson Adams <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Michael Ash <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Draft Proposal for Namespaces in Objective-C (From: Michael Ash <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.