[erlang-questions] Must and May convention

Richard A. O'Keefe ok@REDACTED
Fri Sep 29 00:10:17 CEST 2017



On 27/09/17 10:08 PM, Joe Armstrong wrote:
> For several years I've been using a convention in my hobby
> projects. It's what I call the must-may convention.

The problem with that convention is the English language.

"X must Y" means that either X does Y or there will be
dire consequences for X.  That's the one I would expect
to raise an exception.

"X should Y" means that X ought to do Y but can be
forgiven for failing.  That's the one I would expect
to return {ok,_} or {error,_}.

"X may Y" means that X might or might not Y, either way
I'm easy, failing to Y is not in any sense an error.
I'd expect a result like {aye,_} or nay, where neither
of these is an error.

So your convention is the very worse of what the words
suggest to me.  I would expect

     Data = must_read_file(File_Name)

and

     case should_read_file(File_Name)
       of {ok,Data} -> ...
        ; {error,Reason} -> ...
     end

A nice introduction to deontic logic (the logic of
must/may/should/mayn't and so on) can be found at
https://plato.stanford.edu/entries/logic-deontic/

RFC 2119 is probably of more direct relevance to Erlang
programmers.  https://www.ietf.org/rfc/rfc2119.txt says
(paraphrased)

MUST       an absolute requirement (do or die!)
MUST NOT   an absolute prohibition (die if you do!)
SHOULD     a recommendation (do it if you can)
SHOULD NOT a recommendation against (avoid it if you can)
MAY        an option; it's ok either way.

So I like the idea of such a convention, but I think it
should not confuse people familiar with RFC 2119.




More information about the erlang-questions mailing list