A programming convention

Fredrik Linder fredrik.linder@REDACTED
Tue Jun 11 23:01:56 CEST 2002


> Here's an idea for a programming convention....
[...]
> Now the convention. We always provide a *pair* of interface functions:
>
> lookup(Key, Dict)   -> Value | exit(Why)
> lookupQ(Key, Value) -> {ok, Value} | {error, Why}
>
> The "Q" in the name signifies "Query" or "Question" in other words we do
not
> *know* if the function will work or not - this is the expected behavior
> of the function.
>
> Without the Q the function must work. The relationship is obvious
>
> lookup(Key, Dict) ->
>     case (catch lookupQ(Key, Dict)) of
> {'EXIT', Why} ->
> {error, Why};
> Other ->
> {ok, Other}
>     end.
>
> We also say that functions with a Q at the end of the name *always*
> return maybe() types << maybe() = {ok, Val} | {error, Why} >>
>
> If we do all this we will *finally* be able to define an error in a
program
> as a "top level untrapped exit"
>
> Comments welcome

Personally I do not believe such a convention would work... There are just
too many non-disiplined programmers out there. (:-) Your <flame> comment
about retruning booleans really points that out.

However, I do like the wrapper function proposed by Ulf Wiger.





More information about the erlang-questions mailing list