[Tutor] Restricting the type of passed-in objects

Remco Gerlich scarblac@pino.selwerd.nl
Mon, 14 May 2001 01:37:26 +0200


On  0, VanL <van@lindbergs.org> wrote:
> Here is how I came to this project:
> 
> I was thinking about writing a faq generator and maintainer for my work.  While
> thinking about the problem, it occurred to me that a faq could be easily
> represented by a tree of faqEntry objects. 

Wait wait wait - *why* did this occur to you? Is the FAQ itself a hierarchy?

> Then I could also build into each
> entry the knowledge of how to render itself in various formats (html, text,
> whatever).

That's totally independent of the structure being a tree, a hash table, or
whatever. And you might want to have, instead, a HTMLRenderer object or so
that takes the text version of the FAQ. That seems more logical to me, or at
least also worth considering.

> Then I could just call faq.render() on the root of the tree and it
> would recursively call itself to render the whole thing, including all the numbers

Again, that would work for other structures as well, right?

> and hyperlinks (because the relationships would be defined by each entry's
> position in the tree).

Hmmmmm. I think hyperlinks between documents are a lot more complicated than
that. Are you sure you only link between siblings, and between parent/child
pairs?

> After I started to work on that problem (and being a data structures junkie -- I
> just think they are cool) it seemed to me that it would be much better to write a
> general tree class and inherit from it.  Then, I started to think how I could make
> 
> that tree class be as general as possible, so that I could use it in the future to
> 
> represent different types of trees.
> 
> And thus we are here.  If my faq-o-matic works like I hope, I think it would be a
> pretty cool little hack -- It would be the first thing I would consider neat
> enough to submit to Useless Python.

There's no neatness requirement for Useless Python - if you have something
you made and that actually works, it's neat enough.

I don't think a tree is all that natural for a FAQ. I'd go for a dictionary
- each FAQ entry has its own keyword or title, and that's the dictionary
key. Hyperlinks are trivial (they point to another keyword). This goes along
with the first rule of data structures in Python - "Use a dictionary".
Alternatively you might want a list, or some object wrapping either of the
two.

But what's so tree-like about FAQs? They're organized into chapters, but
besides that they're mostly a list of questions...

-- 
Remco Gerlich