[Tutor] Sort of database & "family tree" question

spir denis.spir at free.fr
Thu Feb 5 14:54:49 CET 2009


Le Wed, 4 Feb 2009 22:33:45 -0000,
"Alan Gauld" <alan.gauld at btinternet.com> a écrit :

> 
> "Timo" <timomlists at gmail.com> wrote
> 
> >>>> class Person:
> >>>>      def __init__(self, parser):
> >>>>          self.first  = parser.get(person, 'firstName')
> >
> > Hey Alan, thanks for that explanation!
> >
> > But the class you gave, does almost the same thing as my function.
> 
> That was my point. Its just a prettier way of handling it and slightly
> easier to use sionce you don;t need to quote the field names,
> just use the dot notation.
> 
> > both store the info in a dic, so to retrieve info for a certain 
> > person, we both have to do the same thing. Or am I missing something 
> > here?
> 
> The class is less typing. Youcreate a dictionary of dictionaries,
> I create a dictionary of objects - which are easier to access.
> However the class can also have methods added to do searches,
> follow the tree etc. You could also add the people dictionary as a
> class variable which would add to the conceptual consistency of
> the solution..

[... lots of sensible words comparing dict way to object way ...]

A note on implementing all the features needed for actual use (at least, a nice output format): using a dict of dicts will tend mixing up things related to persons with other, indirectly related things. Unless you keep a very strict design and coding discipline. Many things get uselessly dependant so that minor changes become difficult. Using objects does not guarantee preventing that (especially in python where it is always possible to access any object attribute from anywhere), but it helps much. Actually, it helps both at design and coding levels. But you are still free to write an unreadable mess...

Denis

------
la vida e estranya


More information about the Tutor mailing list