B
Bernhard Brodowsky
Hi,
I heard many times that the visitor pattern is useless in Ruby and
similar things.
However, I'm just writing an interpreter for a small imperative
language. I finished the parser and am just beginning to think about how
to implement the interpreter.
I just thought that it's a perfect place to use the visitor pattern, the
abstract syntax tree is the object structure to be "visited" and the
interpreter is a visitor.
This would have another advantage, namely that I can easily add more
visitors, like for example a pretty printer or something to compare ASTs
(useful for unit tests)
I could just add this functionality to the elements of the AST directly,
but somehow, I don't like this because I always have to search my ~30
classes that represent syntax units and implement one method in each of
them. Instead, it's much more comfortable to just write one new class.
What do you think about that? Is it really that bad to use the visitor
pattern in Ruby? And if yes, what is the reason for this?
I heard many times that the visitor pattern is useless in Ruby and
similar things.
However, I'm just writing an interpreter for a small imperative
language. I finished the parser and am just beginning to think about how
to implement the interpreter.
I just thought that it's a perfect place to use the visitor pattern, the
abstract syntax tree is the object structure to be "visited" and the
interpreter is a visitor.
This would have another advantage, namely that I can easily add more
visitors, like for example a pretty printer or something to compare ASTs
(useful for unit tests)
I could just add this functionality to the elements of the AST directly,
but somehow, I don't like this because I always have to search my ~30
classes that represent syntax units and implement one method in each of
them. Instead, it's much more comfortable to just write one new class.
What do you think about that? Is it really that bad to use the visitor
pattern in Ruby? And if yes, what is the reason for this?