[CPDictionary dictionaryWithObjects:___ forKeys:___];
or
x = [CPDictionary dictionary]; [x setObject:___ forKey:___];
or
[CPDictionary dictionaryWithJSObject:____];
The idea is to provide a new alternative that looks very similar to
JSON:
theDictionary = @{ key:object, key2:object2 };
This would be 100% equivalent to [CPDictionary dictionaryWithJSObject:
{ key:object, key2:object2 }]; In fact, the compiler would just turn
it into this. To have inner dictionaries just continue using the
syntax:
@{ key:object, key2:object2, key3:@{ key:object } };
The dictionary created will still be accessible with objectForKey: and
allow mutation with setObject:forKey:, but I think this will make a
big difference psychologically since dictionaries feel "heavy" right
now, just due to the verbosity of creating them.
Feel free to chime in.
Also how about extending this to arrays where it just becomes @
{object, object, object}. Once the precedent has been set it seems
sensible to extend it to arrays.
> --
>
> You received this message because you are subscribed to the Google
> Groups "Cappuccino & Objective-J Development List" group.
> To post to this group, send email to objecti...@googlegroups.com.
> To unsubscribe from this group, send email to objectivej-de...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/objectivej-dev?hl=en
> .
>
>
function CPDict(object)
{
var keys = Object.keys(object);
var values = keys.map(function(k){ return o[k]; }); // or whatever
return [CPDictionary dictionaryWithObjects:values forKeys:keys];
}
CPDict({ "foo" : "bar" })
etc.
function CPDict(JSObject) { return [CPDictionary
dictionaryWithJSObject:JSObject]; }
But I suppose that is an implementation detail.
The idea behind the syntax is that I think people "feel" like they're
using something heavier than they really are. By adding a syntax
feature it feels more like a base class object on par with Array. For
example, I feel people don't use Sets and OrderedSets, despite being
the appropriate data structure in many cases, simply because its so
easy to create arrays and arrays "feel" so cheap to create.
The other nice thing about syntax is that we could extend JSON in the
same way. People can pass around JSON that includes all the
fundamental data structures of Objective-J. Today this is ambiguous,
your choices without doing significant work yourself are:
1. Turn all {}'s in JSON into dictionaries
2. Turn only the top most {} in JSON into a dictionary
3. Don't turn any {}'s in JSON into dictionaries.
@{} would allow you explicitly differentiate dictionaries from js
objects.
> The other nice thing about syntax is that we could extend JSON in the
> same way. People can pass around JSON that includes all the
> fundamental data structures of Objective-J. Today this is ambiguous,
> your choices without doing significant work yourself are:
>
> 1. Turn all {}'s in JSON into dictionaries
> 2. Turn only the top most {} in JSON into a dictionary
> 3. Don't turn any {}'s in JSON into dictionaries.
>
> @{} would allow you explicitly differentiate dictionaries from js
> objects.
I think it would be a mistake to start using a custom version of JSON. "{}" is already the dictionary type in JSON, and while JSON happens to be a subset of JS, that doesn't mean {} *has* to map directly to JS objects. We could easily implement a Plist encoder/decoder which uses CPDictionary instead of plain JS objects. In most cases I think you'd want option #1 or #3.