[erlang-questions] Erlang style question - input handling
Ben Butler-Cole
ben@REDACTED
Thu Sep 28 11:30:29 CEST 2006
> Nohl Attila Rajmund <attila.rajmund.nohl@REDACTED> wrote:
> > I have a couple of functions which follow this pattern:
> > f(X, Y) ->
> > % collect some data
> > % do something with the collected data
> > .
> >
> > In C/C++/Java I'd insert a code like this
> > between the collecting part and the "do something" part:
> >
> > if (!check1(data1)) return ERROR_CODE1;
> > if (!check2(data2)) return ERROR_CODE2;
> > if (!check3(data3)) return ERROR_CODE3;
Richard A. O'Keefe replied:
> By the way, I have very serious doubts about the interface of this
> function. Why should the caller have to work so hard to figure out
> whether they got a good result or a bad one? The natural thing to do
> in C++ or Java is *NOT* to return an error code but to throw an
> error term
If you're going to abandon the error codes why not go the whole hog and just blow up if the data is wrong:
f(X, Y) ->
data1 = collect_data1(X, Y),
% etc
ok = check1(data1),
% etc
do_stuff_with(data1),
% etc
.
More information about the erlang-questions
mailing list