[erlang-questions] binary_to_term

Valentin Micic <>
Wed Jun 10 19:45:57 CEST 2009

>> You are so kind.  I personally think it is terrible!
>> The issue has been discussed before, both in meetings and in this 
>> mailing list, and my understanding is that there are actually 
>> applications out there which depend on this "feature" (i.e., 
>> binary_to_term/1 succeeding when there is a prefix of the binary which 
>> can be turned into some Erlang term).

>I personally don't see what's so terrible about this behavior.

Well, it is terrible because it is not doing what it is supposed to be
doing. Since you do not expect binary_to_term to return something like this:

binary_to_term(<<131,97,18,131,97,18>>) -> [18, Reminder= <<131,97,18>>]

which would preserve any remaining value, you should not expect it to
consume the reminder either. Or to put it a bit differently, if:

1> catch binary_to_term( <<12>> ).

does crash, so should binary_to_term(<<131,97,18,131,97,18>>).
If we can agree that <<12>> is not an Erlang term, why should we accept that
<<131,97,18,131,97,18>> is?


More information about the erlang-questions mailing list