News for hackers. Stuff that matters.
Re:Software Design Patterns Are Not Goals, They Are Tools by emodendroket on Thursday May 19, 2016 @11:08AM (#11730801)
"Visitor" has always bothered me too. If you look it up it's tons and tons of text to describe "pass in a function and descend a graph calling it on each node."
Re:Software Design Patterns Are Not Goals, They Are Tools by munificent on Thursday May 19, 2016 @01:50PM (#11732117)
That's actually not what the visitor pattern is about, though the way it's typically presented and the poor name tends to confuse the fact. Visitor isn't about traversing trees. It's about letting you define class-specific behavior outside of the definition of the class itself.

It gives you a way to "add a method" to a set of classes without actually stuffing them in the class definitions themselves.

In practice, most visitor patterns are used with AST classes or other types that are stored in a tree-like fashion, but that's coincidence. The visitor pattern itself is really about using virtual dispatch to avoid an ugly and non-type-safe type switch.

Re:Software Design Patterns Are Not Goals, They Are Tools by emodendroket on Friday May 20, 2016 @09:07AM (#11737432)
I'm not sure I'm following what you describe. Like an extension method or mix-in?
Re:Software Design Patterns Are Not Goals, They Are Tools by Munksgaard on Friday May 20, 2016 @03:15AM (#11736035)
So pattern matching?
Re:Software Design Patterns Are Not Goals, They Are Tools by munificent on Wednesday May 25, 2016 @01:30AM (#11767832)
Sort of. It's a way to emulate a simple subset of pattern matching in languages that lack it.
Re:Software Design Patterns Are Not Goals, They Are Tools by gnaritas on Thursday May 19, 2016 @01:24PM (#11731864)
> If you look it up it's tons and tons of text to describe "pass in a function and descend a graph calling it on each node."

No, it's one word: visitor. That's the point, we can now avoid saying "pass in a function and descend a graph calling it on each node" and instead simply say visitor and everyone knows what we mean without the big long explanation.

Re:Software Design Patterns Are Not Goals, They Are Tools by maffydub on Thursday May 19, 2016 @11:17AM (#11730853)
Sure, so some documentation isn't great (and, by having lots of documentation, you might be a bit disappointed at how simple it ends up being).

...but going back to my original point, isn't it more valuable to have a common vocabulary, meaning that I can say "visitor" rather than "pass in a function and descend a graph calling it on each node"?

Re:Software Design Patterns Are Not Goals, They Are Tools by emodendroket on Thursday May 19, 2016 @12:54PM (#11731583)
Well, in my opinion, no, because the fancy terminology obscures the simple idea.

Also, the naming of the pattern, along with implementation, may push people to copy a design that would be the best way to do it in C++ or Java ca. 2000 but unnatural in whatever they're working in.

Re:Software Design Patterns Are Not Goals, They Are Tools by gnaritas on Thursday May 19, 2016 @03:28PM (#11733032)
It's a simple word, visitor; that's not fancy terminology. Giving things names is not fancy, it's practical and it aids in communicating with other people who do the same thing. You're basically objecting to the fact that people like to give names to their idioms so they communicate better.
Re:Software Design Patterns Are Not Goals, They Are Tools by emodendroket on Thursday May 19, 2016 @04:39PM (#11733618)
No, I'm objecting to the use of terms which I feel make communication worse, rather than better. You're free to disagree.