This... I can actually see the point in this. The Visitor pattern is one of those patterns I never really saw the point of, and which mostly struck me as an over-engineered hack about a shortcoming in a language. This example actually makes clear why you'd need to do it this was in C++ at least. Not sure which other languages would need this. It's certainly not pretty. Then again, dispatching twice is not so bad comp…
Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
21–30 of 64 posts
Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#22The thing that annoys me most about this pattern is that people always miss the "there needs to be lots of things you want to perform on those thingies". And so we end up with a huge pile of visitor code, and there is one or maybe two actual visitors. When it would have been far easier to read and modify if it was just coded out normally.
I don't know if I have ever actually seen a true implementation of this pattern. What I have seen is a pattern someone called a Visitor where a tree is iterated over and the "Visitor" makes virtual function calls on the composite node in a single function body without ever doing something different depending on the type of the node.
Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#23Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#24their GDPR compliance screen is full of anti patterns. Will not read.
Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#25Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#26C++ match expressions would make std::variant a really nice alternative. I assume there is already a proposal out?
// Client visitor code
match(
thingy,
[](const PurpleThingy& ) {std::cout
Working example:
https://coliru.stacked-crooked.com/a/dfed39bc7fcdfb01Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#27This... I can actually see the point in this. The Visitor pattern is one of those patterns I never really saw the point of, and which mostly struck me as an over-engineered hack about a shortcoming in a language. This example actually makes clear why you'd need to do it this was in C++ at least. Not sure which other languages would need this. It's certainly not pretty. Then again, dispatching twice is not so bad comp…
[0] https://eli.thegreenplace.net/2016/the-expression-problem-an...
Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#28So annoying. I had to click through 20 slides of a cartoon dog acting weaboo to see the code example and I still don't see why the pattern is bad - which was the initial implication of the post. Why do people bury their thesis in horrible garbage like this? Sometimes I wish people were normal.
Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#29The even deeper problem is what ASTs are meant to represent, to which the answer would be "possibly a lot of diverse things". Diversity is never good in a computational context. But I don't see a good way to avoid it in the context of programming languages and ASTs. The reason for the diversity is that programming languages should allow humans to specify what should happen in very few keystrokes.
Re: Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
#30C++ match expressions would make std::variant a really nice alternative. I assume there is already a proposal out?
std::visit mostly allows you to do that already: https://coliru.stacked-crooked.com/a/be5c44281eea8bc4 Then only unfortunate missing piece of the puzzle is that there's no trivial way to create a closure out of this, so it requires a bit more manual work to propagate local state to the visitor.