[erlang-questions] nand problem
Mon Jan 26 22:53:09 CET 2015
Joe Armstrong schreef op 26-1-2015 om 22:35:
> On Mon, Jan 26, 2015 at 6:26 PM, Hugo Mills <hugo@REDACTED> wrote:
>> On Mon, Jan 26, 2015 at 05:21:42PM +0100, Roelof Wobben wrote:
>>> b_and(true, true) ->
>>> b_and(true, false) ->
>>> b_and(false, true) ->
>>> b_and(false, false) ->
>> You could make this shorter and possibly easier to read with
>> b_and(true, true) ->
>> b_and(_, _) ->
> At which point I feel compelled to ask
> do you really really really want
> b_and(1, any_old_stupid_argument) to evaluate to false?
> 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
> 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
> the principle of least astonishment.
>> i.e. define the (one) special case, and then just say that
>> everything else evaluates to false. You can do something similar with
>> Hugo Mills | Two things came out of Berkeley in the 1960s: LSD
>> hugo@REDACTED carfax.org.uk | and Unix. This is not a coincidence.
>> http://carfax.org.uk/ |
>> PGP: 65E74AC0 |
>> erlang-questions mailing list
Oke, So for you the long version is well. Write every case so when
someone uses something else then true or false will raise a error.
Or do I misunderstood you ?
More information about the erlang-questions