[erlang-questions] Package Support/Use
Mats Cronqvist
mats.cronqvist@REDACTED
Mon Nov 6 11:34:49 CET 2006
Christian S wrote:
> On 11/6/06, Bob Ippolito <bob@REDACTED> wrote:
>> On 11/6/06, Mats Cronqvist <mats.cronqvist@REDACTED> wrote:
>> > Richard A. O'Keefe wrote:
>> > > Dominic Williams <xpdoka@REDACTED> wrote:
>> > > - returning tagged values vs. throwing
>> > i hope you misremember, cause returning tagged tuples is truly
>> abominable.
>> > only a closet C programmer would use that idiom.
>
> How are tagged tuples bad? How do one reason for such an opinion?
as a really dumb example, consider three functions open(Filename),
read(FileDescriptor), and process_data(Data) that can either fail or return
useful data. in C you'd do something like this;
if ( ( fd = open(name)) == NULL ) return -1;
if ( read(fd,&data) == -1 ) return -2;
if ( process_data(&data,&pd) == -1 ) return -3;
return 0;
in Traditional Erlang something like this;
{ok,FD} = open(Name),
{ok,Data} = read(FD),
{ok,PD} = process_data(Data),
in BettErl (tm);
process_data(read(open(Name))),
TradErl is more verbose and binds worthless intermediate variables.
TradErl has poor error reporting.
it will either succeed or fail with "badmatch". not very helpful. the BettErl
function will either succeed or throw useful stuff like {couldnt_open,Name} or
{read_failure,enoent}, because that's how functions are written in BettErl; they
either returns proper data or throws something meaningful.
so, to answer your question, tagged tuples encourages verbose code with poor
error reporting.
in short, bad style. IMO.
mats
p.s. i'm aware there are some oopses in the meta-code (e.g. memory leaks). but i
don't think that has any bearing on my conclusion.
More information about the erlang-questions
mailing list