On 12 Jul 2011, at 14:37, Quentin Mathé wrote:

>>> Nicolas suggested we use Foo* rather than Foo * precisely for this reason. 
>>> I rather like the idea, but it decreases readability too much imo. 
>>> Especially arguments looks less readable in methods declarations.
>>> 
>>> - (NSArray*) emailsForMailbox: (CDCMailbox*)theMailbox;
>>> 
>>> vs
>>> 
>>> - (NSArray *) emailsForMailbox: (CDCMailbox *)theMailbox;
>> 
>> Do we use the latter form?
> 
> Yes, this except is taken from the guidelines.


I just read that section, and I disagree with it entirely.  It also says this:

> Finally always include return type, even if it's id.

I dislike this (and don't use it), because these are NOT type declarations, 
they are cast expressions.  This is why their syntax is the cast expression 
syntax, not the type declaration syntax.  Requiring redundant casts is a bad 
idea.

The examples are also really bad because we're putting the cast expression on 
the argument and the return in different places.  

Objective-C parameter and return types are fundamentally different from C 
function types.  They are not saying 'this value is this type', they are saying 
'this value is something that you can safely cast to this type'. That's an 
important distinction at the language level, and should be reflected in the 
style.  This is why I use this form:

- (NSArray*)emailsForInbox: (CDCMailbox*)theMailbox;

In a C function, this would be written as:

NSArray* emailsForInbox(CDCMailbox* theMailbox);

In both cases, the intent and the underlying semantics are clearly stated.

David

-- Sent from my brain
_______________________________________________
Etoile-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-discuss

Répondre à