<div dir="ltr">I am trying to stick to the rule: if match header longer then 80 chars then I move all<br>the variables bindings to function body, so only necessary to proper matching parts<br>will be left.<br><br>On Tuesday, June 17, 2014 6:21:27 PM UTC+4, Roger Lipscombe wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I'm currently refactoring some code, and I've got something like this:
<br>
<br>handle_foo(#state { type = bar, id = Id }) -> whatever;
<br>handle_foo(#state { type = baz, parent_id = ParentId }) -> whatever.
<br>
<br>...and I'm wondering whether it's considered bad form to access record
<br>fields at the same time as matching them in a function clause. I'm
<br>matching on 'type', and accessing 'id' at the same time, I mean.
<br>
<br>Instead, should I consider something like the following?
<br>
<br>handle_foo(#state { type = bar }) ->
<br>    Id = State#<a href="http://state.id" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstate.id\46sa\75D\46sntz\0751\46usg\75AFQjCNHWepsS8HrDVR37UE3XoGpU4kdS2w';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstate.id\46sa\75D\46sntz\0751\46usg\75AFQjCNHWepsS8HrDVR37UE3XoGpU4kdS2w';return true;">state.id</a>,
<br>    whatever;
<br>handle_foo(#state { type = baz }) ->
<br>    ParentId = State#state.parent_id,
<br>    whatever.
<br>
<br>The first form makes it explicit that for different types, different
<br>fields matter (which might be a smell by itself), but it gets hard to
<br>see the match on 'type' once I'm accessing more than one or two
<br>fields.
<br>
<br>I know this is stylistic, and there's no "right" answer; I just
<br>wondered what other people tend to do?
<br>
<br>Or, more generally, do people prefer using pattern matching to access
<br>record values, or plain-ol' Foo = State#state.foo expressions?
<br>
<br>Thanks,
<br>Roger.
<br>______________________________<wbr>_________________
<br>erlang-questions mailing list
<br><a href="javascript:" target="_blank" gdf-obfuscated-mailto="Lx6gBp-d2pkJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">erlang-q...@erlang.org</a>
<br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions\46sa\75D\46sntz\0751\46usg\75AFQjCNH15VBDH9qL9o1Zx3x6ZeLmwvUvTg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions\46sa\75D\46sntz\0751\46usg\75AFQjCNH15VBDH9qL9o1Zx3x6ZeLmwvUvTg';return true;">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a>
<br></blockquote></div>