proposal for better syntax for extern objective-C and compatibility with named argument parameters

Paulo Pinto pjmlp at progtools.org
Thu Jun 27 05:42:04 PDT 2013


On Thursday, 27 June 2013 at 05:35:28 UTC, Timothee Cour wrote:
> See [1][2] for related thread introducing extern(objective C)
>
> A)
> The syntax proposed in [2] transforms:
> -(void) insertItemWithObjectValue: (NSString *) path 
> atGreen:(NSInteger)
> anInt;
> [obj insertItemWithObjectValue:val atGreen:idx ];
>
> into:
> void insertItem(NSString* object, NSInteger anInt)
> [insertItemWithObjectValue:atGreen:];
> obj.insertItem(val, idx);
>
> B)
> I don't see how it handles this case:
> [obj insertItemWithObjectValue:val atGreen:idx ];
> [obj insertItemWithObjectValue:val atRed:idx ];
>
> obj.insertItem(val, idx); //atGreen or atRed ?
>
> C)
> The fact that one needs to come up with a new name insertItem 
> is not good
> (as done in [2] ). And if we reuse the name:
> 'void insertItemWithObjectValue(NSString* object, NSInteger 
> anInt)
> [insertItemWithObjectValue: atGreen:];'
> Then it's not DRY.
>
> D)
> the variable list is separated from the argument name list; 
> this makes it
> less readable with more arguments.
>
> E)
> the only benefit of objective C's syntax (making it clear at 
> call site what
> is the argument description) is lost.
>
> ----
> F)
> *I'd like to propose instead the following syntax:*
> void insertItemWithObjectValue(NSString* object, NSInteger 
> atGreen:);
> void insertItemWithObjectValue(NSString* object, NSInteger 
> atRed:);
> obj. insertItemWithObjectValue(object, atGreen: idx);
> obj. insertItemWithObjectValue(object, atRed: idx);
>
> Advantages:
> * unambiguous (cf B)
> * no need to come up with new name or repeat it (cf C)
> * no need to separate variables from their submethod name (cf D)
> * more D-like, yet reminiscent of objective C argument 
> description at call
> site (without those fugly objective C brackets)
>
> G)
> Finally, this would be compatible with *named argument parameter
> syntax*that I and others have been pushing for, if they are ever
> introduced in D.
> There were many proposals but I'd like to propose this:
>
> void fun1(int a, int b, int c:, int d:);
> obj.fun1(1, 2, c:3, d:4);
>
> void fun2(int a, int b, int c:3, int d:4);
> obj.fun2(1, 2); => fun2(1,2,c:3,d:4)
> obj.fun2(1, 2,d:0); => fun2(1,2,c:3,d:0)
> obj.fun2(1, 2,d:0, c:6); => fun2(1,2,c:6,d:4)
>
> 'd:' indicates that d argument is mandatory at call site and 
> name d is part
> of the API.
> 'd:4' indicates that d argument is optional at call site and 
> name d is part
> of the API;
> optional named arguments must appear after all other arguments, 
> and can be
> reordered / omitted.
>
> ----
> [1]
> for
> https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CC8QFjAA&url=http%3A%2F%2Fforum.dlang.org%2Fthread%2Fkq7li9%242j9v%241%40digitalmars.com&ei=OMbLUae3LLD0iwLl04CACw&usg=AFQjCNHScB2VEdtBBSnkFKum21Gz3sIUDw&sig2=1ToqlVmg6nDWMMpxPg5Lcg&bvm=bv.48572450,d.cGE
>
> [2]
> http://michelf.ca/projects/d-objc/syntax/#protocols

Have you had a look at how Mono does it for C#?

http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c_libraries

--
Paulo


More information about the Digitalmars-d mailing list