Writing XML

spir denis.spir at gmail.com
Sun Feb 6 15:23:45 PST 2011


On 02/06/2011 10:59 PM, Rainer Schuetze wrote:
> This looks nice and compact Using opDispatch to specify the tag (I guess that
> is what you are using to create a tag "book" by calling xml.book()) feels like
> misusing opDispatch, though. Does it add readability in contrast to passing the
> tag as a string to some function?

About readability, I for one had to thnk really hard ;-)

> How do you write a tag named "tight"? Or a tag calculated at runtime?

Call opDispatch directly ;-)

> Something more conventional would be
>
>      xml.tag("book", attr("year", book.year), { ...

Would prefere that by far. (even if a few chars more verbose: who cares, the 
code here is actually data description, by definition done once and for all?)

> but I'm not sure that pairing the attribute name and value adds readability or
> mere noise.

This raises the same famous issue (repetedly pointed to) as by Lua's tables: 
since they are both objects and collections (and both arrays and AAs, bu the 
way), then there is no way to tell apart attributes (members) from elements 
(coll data), when needed. t.count & t["count"] could /both/ mean attribute 
'count' or element which key is "count". Too bad.
This is for me the issue #1 in Lua's design (#2 beeing precisely 
non-distinction of arrays and AAs, which prevents development of good builtin 
functionality for each, because of conflicting requirements.)

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d mailing list