Avoid newbie record redundancy?

Juan José Sánchez Penas <>
Sat May 27 22:56:02 CEST 2006


Hi,

On Sat, May 27, 2006 at 01:34:01PM -0700, Damien Katz wrote:
> Is the following also acceptable, both functionally
> and stylewise? I find this more readable, but most
> code I see written uses the when clause and
> is_record().
> 
> match_queue(MasterQueue) ->
>  receive
>    { msgPeerMaster, #rcdPeerMaster{} = A } ->
>       match_queue(queue:in(A, MasterQueue));
>    _ ->
>       ?elog("HELP!~n", [])
>     end.

I think both ways of doing it are functionally equivalent in this case.
Besides, with your approach, you could pattern match directly parts of the
record, so it is potentially more powerful: 

     #rcdPeerMaster{field1 = Value1, field2 = Value2, ...} = A.

Stylewise I also think the one you propose is nicer, but I it is very
subjective.

BTW, if I remember correctly, I once read somewhere that using guards is
less efficient than pattern matching directly using the record type. Anyone
could confirm this?

Cheers.




More information about the erlang-questions mailing list