[erlang-questions] erlang-questions Digest, Vol 24, Issue 11

John Haugeland stonecypher@REDACTED
Mon May 4 17:00:34 CEST 2009


>  My $0.02 is that this advice is, and always has been, hogwash. It is
>>  a rare function that can return several valid answers. So, the
>>  default should be to return a valid answer, i.e. one that can be
>>  used directly, or throw an error.
>>
>>  My theory is that the people who wrote this "programming rule" were
>>  (good) C programmers, and thus felt a need to check if the value
>>  returned was ok before they dared use it.
>>
>
> Your theory is incorrect.  The reason keysearch returns tagged result
> values is that the thing you're searching for might have a value of false.
> Tagged results are the only way to return a value such that any value is
> legal; otherwise you need a placeholder value for "nothing found", which is
> not a tolerable admission in basic datastructure behavior.  There is no way
> to guarantee that every legal value in a datastructure can be unambiguously
> fetched without tagging.
>
> Manual advice is correct.  It's generally a bad idea to call the advice in
> the manual hogwash when you're still guessing about the reason it was
> there.  This is honestly pretty 101.
>

Aaaaaaaaaaaand then I drink more coffee, realize that it returns the
complete tuple rather than the field, that I'm thinking of proplists and
that I've made a jackass of myself.  Lovely morning for some dumb, don't you
think?

I retract this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090504/7e91984b/attachment.htm>


More information about the erlang-questions mailing list