On 1/19/07, Quentin Mathé <[EMAIL PROTECTED]> wrote:
Le 18 janv. 07 à 15:03, David Chisnall a écrit :
> The macros Nicolas had were (as I recall):
>
> #define AS ,
> #define D(...) [NSDictionary dictionaryWithObjectsAndKeys:items
> __VA_ARGS__, nil]

#define D(args...) [NSDictionary dictionaryWithObjectsAndKeys: args, nil]
#define MD(args...) [NSMutableDictionary dictionaryWithObjectsAndKeys:
args, nil]
#define INT(arg) [NSNumber numberWithInt: arg]
#define FLOAT(arg) [NSNumber numberWithFloat: arg]
#define AS ,

> You would then use it like this:
> NSDictionary * example = D(foo AS @"foo, bar AS @"bar");
>
> This lets you use dictionaries as a quick substitute for creating
> simple classes that just encapsulate some data.

True, but I'm unsure to really like the use of 'AS', specially
because it's optional and I wouldn't use it personally I think. I
would type D(foo, @"foo", bar, @"bar").

Actually I didn't have AS at first, it's a good suggestion from david
-- after using it a bit I much prefer it. It makes things
clearer/cleaner imho.

It could be more readable to reverse the order of objects and keys
and also to use DICT rather than just D.

I thought about DICT, but D is obviously shorter and well, not common
either so... I figured it would be fine. But if people prefer DICT no
problems -- either way is ok.

The thing is, it depends on your usage of dictionaries; until recently
I didn't use them much, but now I'm using them a lot, as david said,
as substitutes for "data" classes. For that  kind of use you
appreciate shortness. As they are (or should be) an important,
recurrent use, using a one letter name is fine by me.

DICT(@"foo" <- foo,
           @"bar" <- bar)
I like <- better than AS but it's probably not a wise choice since
it's enough distinct from C syntax and doesn't stand as a macro.
D(@"foo" AS foo,
     @"bar" AS bar)
The reversal of object and key order makes it more similar to class
declaration.

Hm... I prefer the current direction; beside reversing the order will
be difficult :)

We could eventually introduces A(foo, bar) to create an autoreleased
array.

yes, if we have D(), A() makes sense...

I think it would be more useful to return mutable collections than
immutable as D currently does.

I have a MD macro for that.

--
Nicolas Roard
"La perfection, ce n'est pas quand il n'y a plus rien à ajouter, c'est
quand il n'y a plus rien à retrancher." -- Antoine de St-Exupéry

_______________________________________________
Etoile-dev mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-dev

Reply via email to