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

Motiejus Jakštys desired.mta@REDACTED
Tue Jan 27 09:56:47 CET 2015


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?

Motiejus


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



More information about the erlang-questions mailing list