[erlang-questions] Design patterns?
Garrett Smith
g@REDACTED
Tue Mar 3 14:45:20 CET 2015
A quick thought on the case vs function question...
I personally tend to eventually replace case expressions shortly after
writing them as at that point it becomes clearer to me "what's going on"
there. If a well named function can clarify what's gong on, I'll use it.
Otherwise I leave the case expression alone.
I end up with very few case expressions.
I think the example you give - translating the shape of some result - is
arguably a good one for sticking with case... As a function can start to
take more effort to understand at a glance than the case.
I'd stick with the rule "make it obvious what's going on" and use your best
judgment along the way. If you're working with a team, see what people like
over time and converge on that.
On Mar 2, 2015 8:21 PM, "Judson Lester" <nyarly@REDACTED> wrote:
> As I'm becoming more comfortable and proficient in Erlang, I'm finding
> there there are interesting patterns that begin to emerge that I'm not sure
> I've seen elsewhere. I'm wondering if there's a collection somewhere, maybe
> c2 style?
>
> One example is a complicated data processing: I've started creating a
> special purpose record and dispatching based on its fields. That includes
> short-circuiting on errors, constructing syntheses from simpler data, etc.
> Since I've stumbled onto it, I've been really liking how it can bring the
> full force of pattern matching to complex processing. I do worry that it's
> a bit of a smell though. If the processing can be simplified, that might be
> better, but it's better, imo, than a long ladder of
> maybe_compute_other_thing style functions.
>
> And an open question (for me): when to use case/if versus function heads?
> Roughly, I've been using cases to reformat the returns of a function call,
> but the decision trips me up every time.
>
> Judson
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150303/17c33c2d/attachment.htm>
More information about the erlang-questions
mailing list