[erlang-questions] handling bugs in the program (was: nand problem)

Joe Armstrong erlang@REDACTED
Tue Jan 27 10:14:06 CET 2015


On Tue, Jan 27, 2015 at 9:56 AM, Motiejus Jakštys <desired.mta@REDACTED> wrote:
> On Mon, Jan 26, 2015 at 10:35 PM, Joe Armstrong <erlang@REDACTED> wrote:
>> by explicitly requiring the arguments of b_and to be true or false
>> *and nothing else* you ensure that a program calling b_and with stupid
>> arguments will crash *as soon as possible* which will make debugging
>> easier. It also enables a whole bundle of compiler optimisations -
>> making arguments more general than they need to be makes analysis more
>> difficult
>> and compiled code more general. The more you tell the compiler, then
>> better code it can produce.
>>
>> Yes the program is shorter (good) - but it's not totally correct (bad).
>>
>> This is not important for small programs, but for huge programs making every
>> function totally correct is essential - correct well typed code can be written
>> stuck in a library and forgotten forever - code that does silly things
>> with silly
>> arguments is not good programming practise.
>>
>> b_not should be defined over boolean arguments - any non boolean
>> argument should raise an exception *immediately* anything else
>> violates
>> the principle of least astonishment.
>
> Hi Joe,
>
> does this also apply to messages which receiver is not expecting to
> receive? If an unexpected message is received by a server, should it
> crash?
>
> In other words, should this[1] be exit(badarg) instead?

No necessarily - it depends upon the protocol. You'd have to
distinguish out-of-order messages from incorrect messages. I guess
incorrect messages should crash both the sender and the receiver. Out
of order messages
may or may not be a problem depending on the logic of the program
so there is no automatic "right thing to do"

/Joe

>
> Motiejus
>
>
> [1]: https://github.com/joearms/elib1/blob/a4e794d506ba39be14fef7ada10826c2c1b0f947/src/gen_component.erl#L88



More information about the erlang-questions mailing list