ok or true? (fwd)
Joe Armstrong
joe@REDACTED
Mon Feb 23 11:54:51 CET 2004
Things that return two possible atoms should *always* return true | false.
Why? - because there are loads of library routines which work on
predicates.
Suppose you have a function switch_status(...) what returns on | off.
I'd *immediately* rename this as
is_swich_on(...) or switchP(...) that returns true | false
Then I can use this as an argument to other Hofs
filter(fun is_swich_on/... )
By sticking to bools you increase the chances of being able to use
the library functions.
In general you should stick to regular return values like
{ok, Val} | {error, Why}
{value, V} | error
for the same reason
/Joe
> This has got to be an age old question:
>
> Return 'ok' or 'true' on success?
>
> I'm building a gen_serial module. Looking at the gen_tcp API, the
> functions return 'ok' when they succeed. Looking at the port BIF API,
> the BIFs all return 'true' when they succeed.
>
> So which is it? :-)
>
> I've finally got async serial port IO working on Windows XP. I need
> to get error handling in, and properly terminate the external port
> servers when the port is closed down, write some edoc, and then I'll
> release it to the list. Should be sometime later this week.
>
> I'd like to get the current serial contrib merged in with this driver
> too, so both Windows and UNIX can use the same Erlang code.
>
--
-------------------------------------------------------------
Lennart Ohman phone : +46-8-587 623 27
Sjoland & Thyselius Telecom AB cellular: +46-70-552 6735
Sehlstedtsgatan 6 fax : +46-8-667 8230
SE-115 28 STOCKHOLM, SWEDEN email : lennart.ohman@REDACTED
More information about the erlang-questions
mailing list