3 ms·
>I am honestly amazed you could interpret it that way, rather than the intended: it seems like a questionable design pattern. "Design patterns are bad" is an o
by coldtea 6y ago
>I am honestly amazed you could interpret it that way, rather than the intended: it seems like a questionable design pattern.
"Design patterns are bad" is an often repeated "folk wisdom" in dev circles. So by under-definining what's meant (leaving it open to interpretation) it's a very easy intepretation for others to assume of the comment.
The wording supports this too:
"has an element of pattern-smell (and by pattern I mean design pattern)"
This doesn't seem to imply "questionable design pattern", but "this smells like a pattern", and given that you object to it, one assumes that for you "smelling like a pattern" is bad.
Also, "seems like a questionable design pattern" would be a bizarre interpretation to take -- as this is a first-class syntax, not a design pattern.
>To me it sort of implies a function is serving multiple purposes, essentially multiple functions mashed into one -- and you figure out what really happened by the shape of it's return value. It seems to go against everything we think of functions as pure-as-possible constructs that do one thing well, and that is represented by a clearly defined return value.
I see where you're coming from, but there's nothing really violating purity here, or even "clearly defined return values".
Those clearly defined return values could still take several variations of a shape or even several shapes. Those won't have to be arbitrary shaped or non-pure. It's about handling a class of shapes.
AST nodes for example from a parsing function, protocol parts from a protocol handler, network responses in a server that might or might not have a payload, game states in a logic loop, and so on, fall into this. And pattern matching allows you to handle this common need easily.
So it's not like (pseudocode):
match(foo):
foo ~= duck: ..
foo ~= 5: ..
foo ~= "a string": ..
foo ~= triangle: ..
but more like:
match(astNode):
foo ~= expression: ..
foo ~= statement: ..
foo ~= variable: ..
and other such cases...