durusmail: quixote-users: Generalizing form/widget API a bit
Generalizing form/widget API a bit
2003-11-25
2003-11-25
2003-11-25
2003-11-25
2003-11-25
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-26
2003-11-29
2003-11-30
2003-11-26
2003-11-26
2003-11-26
Patch: add html_attrs keyword arg to widget classes
2003-11-30
Patch: add html_attrs keyword arg to widget classes
2003-12-01
Patch: add html_attrs keyword arg to widget classes
2003-12-01
Patch: add html_attrs keyword arg to widget classes
2003-12-01
2003-12-02
2003-12-03
2003-12-02
Patch: add html_attrs keyword arg to widget classes
2003-12-01
Patch: add html_attrs keyword arg to widget classes
2003-12-01
Generalizing form/widget API a bit
Martin Maney
2003-11-26
On Wed, Nov 26, 2003 at 08:56:53AM -0600, Skip Montanaro wrote:
>     >>> attrs(class_='foo', xml__lang='english')
>     {'xml:lang': 'english', 'class': 'foo'}
>
> It's a bit ugly, but is it less ugly than the alternatives?  What are the
> alternatives?

Unless I missed something (1), all this is to avoid typing a couple of
quotes around the keys in a dictionary literal, no?  Which seems really
pretty stupid to me, since I would think that when you're using per-tag
attributes you'll likely use the same set of attributes repeatedly, so
wouldn't it be nicer to write the dictionary once and reuse it (and
then the API is just a single dict argument, of course)?  So why
confuse things with the stupid trick that makes you have to remember
artifical rules about when to use underscores; why not write just what
you mean (2) and be done with it?

Or maybe the interface should be, or allow, a sequence of (tag_name,
tag_value) pairs like the one that the dict builtin actually has in
2.2.  That might be more convenient if you're resisting CSS for some
[perhaps good] reason and need a lot of boilerplate attributes with a
sprinkling of additions: base_attr + [('magic','42')] being easier for
a once-off than modifying base_dict.


(1) please point it out if I have - I've been guessing some about the
details of the context here as I [still] haven't used this part of
Quixote much.  Where I use attributes - and I've been migrating to a
more CSS/xhtml approach lately - they're generated by data-driven code
along with the rest of the tag.

(2) there's room for debate, I suppose, but the set-of-attrs:python_dict
mapping seems very natural and obvious to me.  I have always been a
little bit amazed, once the obligatory oohing and ahhing over the
cleverness of the kwargs->dict hack had passed, that such a silly and
unobvious thing (3) could be championed by people who regularly complain
that someone else's idea doesn't meet the "explicit is better than
implicit" or "one obvious way" tests.  Sauce for the ox...  :-/

(3) referring only to abusing the **kwargs mechanism in a do-nothing
function as a keystroke saver; as a mechanism for collecting unmatched
keyword arguments within a function it seems like the one obvious way
to do it.

--
To be alive, is that not to be
again and again surprised?  -- Nicholas van Rijn


reply