[erlang-bugs] Document of lists:append/2

Loïc Hoguin essen@REDACTED
Mon Feb 10 10:11:19 CET 2014


Ensuring that input is correct is a lot harder to do than relying on 
Dialyzer. Checking that you have a list is easy, checking that you have 
a list of ascii characters is hard and expensive. You can rarely check 
more than the outer layer of the arguments because it's otherwise very 
expensive. You have to rely on Dialyzer to make sure that was is passed 
is actually the correct type. Since you have to rely on Dialyzer, why 
not speed up your program a little by removing the half-assed checks and 
using Dialyzer for them instead?

A notable exception to that is when your function has side effects. You 
usually don't want to start saving data to a database if it's going to 
fail further down the line, for example.

On 02/10/2014 07:37 AM, Heinz Nikolaus Gies wrote:
> I somewhat disagree on that point. Shouldn’t functions crash given badly
> typed inputs? That sounds like the reasonable thing to to when following
> the fail early paradigm and I always got the impression a lot of the
> functions in the core libraries happily die a tragic death if a wrong
> input comes too close to them.
> ---
> Cheers,
> Heinz Nikolaus Gies
> heinz@REDACTED <mailto:heinz@REDACTED>
>
>
>
> On Feb 9, 2014, at 11:43 PM, Bob Ippolito <bob@REDACTED
> <mailto:bob@REDACTED>> wrote:
>
>> If you assume that all functions have undefined behavior when given
>> incorrectly typed inputs, it's perfectly consistent. Erlang code tends
>> to assume correctly typed input because it's simpler to implement and
>> the types can often be checked mechanically with tools such as dialyzer.
>>
>> On Sunday, February 9, 2014, Yoshihiro Tanaka <hirotnkg@REDACTED
>> <mailto:hirotnkg@REDACTED>> wrote:
>>
>>     Right. I guess I'm questioning the accuracy of the document.
>>
>>
>>     On Sun, Feb 9, 2014 at 7:52 PM, Siraaj Khandkar
>>     <siraaj@REDACTED
>>     <javascript:_e(%7B%7D,'cvml','siraaj@REDACTED');>> wrote:
>>
>>         This is just a surprising side effect of dynamic typing. To
>>         perform the
>>         append, the left list is traversed and the right is just
>>         blindly used as
>>         a tail, so it is never introspected and thus never has an
>>         opportunity to
>>         crash.
>>
>>
>>         On 2/9/14, 10:30 PM, Yoshihiro Tanaka wrote:
>>         > Hi,
>>         >
>>         > In the document
>>         :http://www.erlang.org/doc/man/lists.html#append-2
>>         > It says:
>>         > append(List1, List2) -> List3, List1 = List2 = List3 = [T],
>>         T = term.
>>         >
>>         > But considering the following behavior, it does not look
>>         correct:
>>         >
>>         > 1> [] ++ undef.
>>         > undef
>>         > 2> undef ++ [].
>>         > ** exception error: bad argument
>>         >      in operator  ++/2
>>         >         called as undef ++ []
>>         > 3> [a,b] ++ undef.
>>         > [a,b|undef]
>>         > 4>
>>         >
>>         >
>>         > Thoughts ?
>>         >
>>         >
>>         > Thank you
>>         > Yoshihiro
>>
>>
>> _______________________________________________
>> erlang-bugs mailing list
>> erlang-bugs@REDACTED <mailto:erlang-bugs@REDACTED>
>> http://erlang.org/mailman/listinfo/erlang-bugs
>
>
>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs
>

-- 
Loïc Hoguin
http://ninenines.eu



More information about the erlang-bugs mailing list