Wed Jun 10 18:04:01 CEST 2009
Claes Wikstrom wrote:
> 1> B = term_to_binary(18).
> 2> B2 = <<B/binary, B/binary>>.
> 3> binary_to_term(B2).
> opinions anyone ?
> I for one don't like the above.
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).
This means that you can take some binary and add anything to its end and
binary_to_term/1 will still succeed:
1> B = term_to_binary(42).
I have trouble appreciating why people should not get what they deserve
for relying on this property, but I am sure you've heard the arguments
for backwards compatibility before...
But being in academia, I can perhaps afford the luxury to not care much
about these things. I definitely vote for changing it and have it throw
an exception instead.
More information about the erlang-questions