[erlang-questions] is_integer should always be used?

Lev Walkin vlm@REDACTED
Wed Jul 2 11:06:01 CEST 2008


not norwegian swede wrote:
>   when programming erlang, should i always use is_integer if a float 
> will make the function crash?
> 
> 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.
> 
> if some one passes a float to a function that only takes integers, 
> should i catch that exception or should i let the program crash?


is_integer() is likely to make a program crash, if there are no
suitable alternatives. so, if passing a float _always_ makes
the program crash, then it does not matter where it crashes
much most of the time.

however, it may constitute a good documentation artifact to
have an is_integer() guard around, just to warn the future
readers of your code about function's acceptable domain.

-- 
vlm



More information about the erlang-questions mailing list