On May 20, 2008, at 6:06 AM, Stefan Behnel wrote:

> Martin C. Martin wrote:
>> Recently there was some mention of using the visitor pattern to visit
>> every node, versus a recursive overloaded function.  What do  
>> people see
>> as the advantage of one over the other?  The recursive way seems
>> simpler, but recursion in general is confusing to many, so the  
>> visitor
>> pattern might be easier to understand.  Is there any other trade off?
>
> One of the differences is that one is currently in place while the  
> other
> requires a large refactoring.
>
> Apart from that, I don't see a major (dis-)advantage of either of  
> the two,
> although I might find the recursive approach simpler as well (or at  
> least
> more obvious).

I don't think either is easier to understand, but here's my take on  
the advantages of visitors:

1) Adding a phase doesn't require adding a new function to every node  
in the tree. This is especially nice for making more granular phases  
(such as separating type analysis from coercion from temp variable  
allocation), and things like optimization "phases" that may only need  
to deal with a small subset of the nodes.

2) The visitor pattern allows more flexibility in mutating the tree.  
For example, the mutate_into_name_node function of AttributeNode  
could be handled more naturally. More complex transformations (such  
as handling the with statement) could be handled as well.

Neither of these are compelling enough reasons to throw out the  
current model, but they are worth considering as we go to add new code.

(I just now read Dag's email, which is in general agreement with the  
above.)

  -Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to