consider following code segment

  def valid_row?(%{"acu" => acu}) when is_number(acu) do
    acu_limit = Application.get_env(:beam_checker, :acu_limit)
    acu > acu_limit
  end

since elixir/erlang comparison operator is very broad, the above code will 
never throw any exception irrespective of what is the data type or value 
for acu and acu_limit. But the end result is totally unexpected in cases 
where wrong types are supplied. two actual error cases which happened (and 
took some time to discover due to no exception) :
1) acu_limit was not defined in config, hence acu_limit got value nil
2) acu_limit was defined as string value in config

possible options for discussion:
1) can we have Integer.compare and Float.compare functions. That way 
whenever numeric comparisons are needed, these dedicated functions can be 
used. (preferred)
2) strict comparison version of > and < operators (something along the 
lines of == and ===, but for comparison)

option not for discussion
1) make a private comparison function, which throws an error if input 
values are not numbers. this is what I currently did.

thanks 
miwee  

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/12de7677-e191-4752-9128-9df959c2058b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to