[erlang-questions] is_integer should always be used?
Fri Jul 4 00:11:36 CEST 2008
not norwegian swede a écrit :
> when programming erlang, should i always use is_integer
> if a float will make the function crash?
I think not. I think guards should not be used for type
checking, but used to write different clauses, when you want
to handle floats and ints differently.
Of course, I use test-driven programming, so I don't need
type checking for correctness. And the tests I write are
better at expressing how I intend the function to be used
than a mere guard. And adding a guard for optimisation's
sake would be premature, without profiling.
So, as a general rule, I let it crash, I don't use a guard.
> i havent used so much exception-prevention in erlang and
> it seems the language needs a lot of extra code stuck it
> in ebcause of this.
You must not be coding in Erlang the same way as I. I have
never had as little exception-handling code as when I code
More information about the erlang-questions