[getdns-api] Getting from dicts by subscript operator
Wessels, Duane
dwessels at verisign.com
Mon Sep 21 18:26:20 CEST 2015
Willem,
I think this idea is really great!
> On Sep 18, 2015, at 2:13 AM, Willem Toorop <Willem at nlnetlabs.nl> wrote:
>
> Dear getdns API designers,
>
> Getting into the specific parts of getdns data structures (notably the
> response dict) can be cumbersome in C. Take for example this
> (relatively short) example on how to get to the AD bit of the first
> reply of a response:
>
> getdns_list *replies_tree;
> getdns_dict *reply;
> getdns_dict *header;
> uint32_t ad;
>
> if ((r = getdns_dict_get_list(resp, "replies_tree", &replies_tree)))
> return r;
> else if ((r = getdns_list_get_dict(replies_tree, 0, &reply)))
> return r;
> else if ((r = getdns_dict_get_dict(reply, "header", &header)))
> return r;
> else if ((r = getdns_dict_get_int(header, "ad", &ad)))
> return r;
>
>
> Also, getting data members by text strings like getdns does, is
> unconventional in C libraries, but makes getdns very flexible and easy
> to extend. It also maps very well to modern scripting languages
> (python, javascript, perl, ruby etc.).
>
> Why don't we take this approach one step further, and get to the data
> members by allowing the text strings to contain subscript operators into
> the sub-dicts and sub-lists?
>
> To do the same as the example above with subscript operator:
>
> uint32_t ad;
>
> if ((r = getdns_dict_get_int(resp, "replies_tree[0][header][ad]", &ad)))
> return r;
>
> The conciseness and thereby clarity and readability is increasingly more
> prominent with more involved examples.
>
>
> What do you think?
>
> -- Willem
> _______________________________________________
> spec mailing list
> spec at getdnsapi.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4676 bytes
Desc: not available
URL: <http://getdnsapi.net/pipermail/spec/attachments/20150921/9dc2db58/attachment.bin>
More information about the spec
mailing list