[erlang-questions] What is best practice (records/tupples)?

Abdul Fattah Mahran <>
Mon Feb 6 18:10:48 CET 2012


Hi Matthew,
You are right, the first on is better because you check the length and
assign the variable in one time. and it is a good practice if the contents
of the record are small.

/Abd El-Fattah

On Mon, Feb 6, 2012 at 6:52 PM, Matthew Evans <>wrote:

>
> Hi,
> Given something like:
> -record(my_record, {aaa,                    bbb,                    ccc,
>                   ddd}).
>
> What is more efficient, and what is best practice?
> This -
> some_function(#my_record{aaa = AAA, bbb = BBB, ddd = DDD} = _MyRecord) ->
>   % Some work
>
> Or this -
>
> some_function(MyRecord) ->    AAA = MyRecord#my_record.aaa,    BBB =
> MyRecord#my_record.bbb,    DDD = MyRecord#my_record.ccc,    % Some work
>
> I've always thought that the first example is best. Or does the compiler
> do some kind of trickery?
> Does it make any difference if you only need a few vs. all the variables
> from the record?
> Thanks
> Matt
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Thanks
Best Regards,
Abd El-Fattah Mahran
http://www.linkedin.com/in/abdoomahran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120206/ebd08fd6/attachment.html>


More information about the erlang-questions mailing list