[erlang-questions] eep: multiple patterns
Andras Georgy Bekes
bekesa@REDACTED
Tue May 27 14:36:19 CEST 2008
Hi,
> To me, what we can write now in Erlang as it stands,
> separating "what are the actions" from "what are the names for the
> actions", is easier to read and understand than anything using
> multiple patterns would be,
OK, you showed us (again?) that a possible use of multiple patterns can
be substituted with something else. It always can be done, and
everybody knew that.
Following your way of thinking, we'd conclude that the 'case' construct
is not needed because it can be substituted with auxiliary functions.
Still we have the 'case' construct and like it.
> not because multiple patterns are a bad idea as
> such, but because combining multiple *complex* patterns into a single
> match makes the code harder to read.
That's subjective. To me, the multiple patterns version reads better.
> Multiple *simple* patterns might make for a more interesting example.
OK, you asked for real-life examples. OK, simple pattern.
Here it is, straight from AXD301. I've replaced the "interesting" parts
with foo, bar and baz. Everything else is original.
----------------------------------------
case classify_Foo(Foo) of
undefined_Foo -> bar(); % lots of code here
{meaningful_Foo, Bar, Baz} -> baz(Bar,Baz) % lots of code here
end,
...
classify_Foo(undefined) ->
undefined_Foo;
classify_Foo({undefined, _, _}) ->
undefined_Foo;
classify_Foo({Bar, Baz}) ->
{meaningful_Foo, Bar, Baz};
classify_Foo({Bar, Baz, _}) ->
{meaningful_Foo, Bar, Baz}.
----------------------------------------
How do you like it?
I prefer the multiple patterns version.
(Don't tell me the problem is with the data structures. We all know
AXD301 is garbage :-) but still, our users like it.
Georgy
More information about the erlang-questions
mailing list