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

mats cronqvist masse@REDACTED
Mon May 4 17:25:16 CEST 2009


John Haugeland <stonecypher@REDACTED> writes:

>     > In the "programming rules"
>     > http://www.erlang.se/doc/programming_rules.shtml#REF32551
>     >
>     >
>     > ---snip--------------------------------------
>     > Use tagged return values.
>    
>      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.

  My theory is likely incorrect, but the only thing keysearch can
  find is tuples.

> 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.

  Perhaps you missed the bit where I said "or throw an error"? 18 lines
  or so up? But thanks anyways for the interesting lesson on basic
  datastructure behavior!

> 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.

  Well, I did say it was my $0.02, i.e. I was expressing an opinion. 

>   This is honestly pretty 101.

  And thanks for your refreshing honesty! Alas, I am unfamiliar with
  this "101", although I hear she's pretty.


  mats 



More information about the erlang-questions mailing list