Identifying a class type - bad practice?
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Wed Aug 19 05:39:07 EDT 2009
James Harris a écrit :
> On 18 Aug, 21:50, Chris Rebert <c... at rebertia.com> wrote:
(snip)
>> class node_type_1:
>> def walk_tree(self):
>> #code
>> self.subtree.walk()
>>
>> class node_type_2:
>> def walk_tree(self):
>> #code
>> self.subtree.walk()
>>
>> #etc
>
> Interesting idea.
Basic OO stuff, really. I'd say it's even the whole point of OO.
(snip)
> The tree is for a compiler. Initially the tree is for parsing of
> source code. Then it will need to be processed and changed as further
> compiler phases are written. I don't know yet whether it will be
> easier to modify the tree or to create a new one for each phase.
>
> So I guess whether I use the idea depends on the commonality of
> operations.
You may want to have a look at the "composite" and "visitor" design
patterns. AST are canonical use case for these patterns.
HTH
More information about the Python-list
mailing list