3 ms·
Design patterns are just a convention; I would be as uncomfortable overusing them as jumping on the current pattern bashing fad. The Interpreter pattern is jus
by charlysl 8y ago
Design patterns are just a convention; I would be as uncomfortable overusing them as jumping on the current pattern bashing fad.
The Interpreter pattern is just a technique for doing what amounts to pattern matching but in an OO language, the Visitor is its dual, and Composite is handy to represent arbitrary arity trees.
They allow you to represent algebraic types in an OO language, and I guess that they are design patterns because they can be applied systematically in any domain without having to reinvent the wheel, given that designing with them is driven by the information's structure only, just like in regular FP languages.
Abusing them is just as bad as abusing any other design technique, but when applied correctly they greatly improve program structure and maintainability.
Visitors have nothing to do with multimethods. Their purpose, in this context, is to improve maintainability when in a given functional program written in an OO language you would be more likely to add new functions rather than data type variants; Interpreter would be preferable when the opposite is the case.
Do you know of better ways of systematically doing FP design in C++? The article doesn't mention any.
- nurettin 8y agoThe article isn't about design patterns, it is about using the new functional programming primitives which C++ relatively recently acquired through the standardization process. Suggesting to use a syntax for lambda or currying or transferring closure parameters or making copies of data in order to avoid thread problems is not remotely within the same category as "visitor pattern".
- charlysl 8y ago> it is about using the new functional programming primitives which C++ relatively recently acquired through the standardization process. Sorry, I couldn't find any mention of such new primitives in the article. Which are they?