[erlang-questions] string:substr/2 gives confusing error message

mats cronqvist <>
Fri Dec 5 14:11:03 CET 2008


"Hynek Vychodil" <> writes:

> Because:
>
> Adding exception raise in this case is typical defensive programming
> and it is not good practice in Erlang except pattern match with
> tagging.

  so, a function raising an exception when given bad data is not good
  practice in Erlang? what gave you that impression? I'd say that the
  opposite is true. "The erlang way", as i was taught it, is to fail
  early and let the supervisor sort it out.

  also, the way i interpret "defensive programming" is when a function
  continues despite being given bad data. a typical example would be;

 string:substr("a",2) -> []

 The fact that

 string:substr("a",2)

and 

 string:substr("",2)

  behaves differently is is just silly. the best would be is they both
  failed with badarg. second best if they both returned [].

  mats



More information about the erlang-questions mailing list