[erlang-questions] Trouble with Erlang's lenient comparisons

Richard O'Keefe ok@REDACTED
Thu Apr 14 02:10:24 CEST 2011

On 13/04/2011, at 9:08 PM, JohnyTex wrote:
> I've inherited someone else's code base; sometimes I forget that a
> function returns a tuple and I up comparing it with an integer or
> similar, and get weird behaviour and hard-to-find bugs as a result.
> What's the best way to prevent this?

There are two somewhat different questions lurking here.

- what's the best way to ensure that such mistakes are caught?

  You've mentioned EUnit and Dialyzer, and they are excellent
  for this.

- what's the best way to avoid making such mistakes in the first place?

  Clear, consistent, informative naming conventions.
  Consistent "algebraic" interface design.
  Well thought out policy on when to return "oops" as a result
  and when to raise an exception -- this is still contentious,
  the point here is that you want to *know* the choice a
  function made without having to think too much about it.

Perhaps you could provide an example of a function that returns a
tuple that you want to compare with an integer.

More information about the erlang-questions mailing list