<html><head></head><body>Why not to use different records for different contents? <br>
-- <br>
Best wishes,<br>
Dmitry Belyaev<br><br><div class="gmail_quote">On 18 June 2014 12:21:15 AM AEST, Roger Lipscombe <roger@differentpla.net> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">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">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 /><hr /><br />erlang-questions mailing list<br />erlang-questions@erlang.org<br /><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br /></pre></blockquote></div></body></html>