[erlang-bugs] bug in erlang:size
Sat Aug 4 14:16:26 CEST 2012
----- Original Message -----
> On 08/03/2012 11:12 AM, Joe Armstrong wrote:
> > I think this is a bug:
> > $erl
> > 1> B =<<1:17>>.
> > <<0,0,1:1>>
> > 2> size(B).
> > 2
> > B is not a binary or tuple to size(B) should give badarg
> There is indeed something fishy in the above...
> But IMO, size/1 is one of these functions that should be considered
> deprecated and only kept for backwards compatibility. These days
> exist built-in functions tuple_size/1, byte_size/1, and bit_size/1
> are unambiguous and more type-friendly.
> I would urge Joe to avoid mentioning the existence of size/1 in the
> edition of his book.
I agree with Kostis here. Don't mention it or if he does mention it then it should be so they can understand old code but with a word of warning not to use it.
I understand why it should work with bit strings, it would be strange if it didn't as it works on binaries. Though I think it should return 3 not 2, as byte_size/1 does for the same bit string in R15B01.
More information about the erlang-bugs