[erlang-questions] behavior of lists:append/1

Mikael Pettersson mikpelinux@REDACTED
Mon Sep 16 10:41:05 CEST 2019


On Mon, Sep 16, 2019 at 9:54 AM Lukas Larsson <lukas@REDACTED> wrote:
>
>
> On Sun, Sep 15, 2019 at 8:02 PM Karlo Kuna <kuna.prime@REDACTED> wrote:
>>
>> Michal,
>> i really prefer crashing than garbage in, garbage out policy.
>>
>> also it would be nice if someone from OTP team confirms if stdlib has "garbage in garbage out" policy. i can certainly see benefits of it but in this case fix is easy and small.
>
>
> It is impossible to guard against every possible faulty input, so yes, we do have "a garbage in, garbage out policy". However, we do try to guide the user to write correct code where possible without losing too much performance. Where to draw the line of what "too much performance" means is a constant debate as shown by the other answers to your question.

The bottom line, if I may draw on ROK's comment, is that runtime type
checking adds a measurable cost, generally O(size of term), in
dynamically typed languages.  Adding such a check when not necessary
for the actual operation in question would be a performance bug, and
could easily even raise the asymptotic complexity of the code
involved.  That's why dynamically typed languages generally do not do
any more type checking that absolutely necessary.



More information about the erlang-questions mailing list