[erlang-questions] Must and May convention

Karlo Kuna kuna.prime@REDACTED
Wed Sep 27 12:45:34 CEST 2017


> But the source would be ugly

parse transformations could help

anyway i am against using prefixes (or suffixes) as they encode information
that might be useful for tools as well as humans

i view code as interface to the tools and not to the humans. Ideally one
should write piece of code with tests and documentation
and after review period it should be used and forgotten, and only interface
from  documentation should be consulted

so i would prefer to put information about throws also in function
specifications

On Wed, Sep 27, 2017 at 12:12 PM, Roman Galeev <jamhedd@REDACTED> wrote:

> Well, Erlang sources aren't the prettiest anyway, IMO mostly due to
> function composition syntax.
>
> On Wed, Sep 27, 2017 at 12:10 PM, Joe Armstrong <erlang@REDACTED> wrote:
>
>> But the source would be ugly
>>
>> I want to write
>>
>>     must_read_file(F)
>>
>> and not
>>
>>     must(file,read_file,[F])
>>
>> /Joe
>>
>> On Wed, Sep 27, 2017 at 11:39 AM, Roman Galeev <jamhedd@REDACTED> wrote:
>>
>>> Imo you can do it with:
>>> must(M,F,A) ->
>>> case erlang:apply(M,F,A) of
>>> {ok, Res} -> Res;
>>> _Err ->
>>> io:format("Error ~p:~p(~p) ~p",[M, F, A, _Err]),
>>> exit({must, F, A,})
>>> end.
>>>
>>> In this case, you don't need to make new functions out of existing ones,
>>> and still get a nice error message.
>>>
>>> On Wed, Sep 27, 2017 at 11:30 AM, Karlo Kuna <kuna.prime@REDACTED>
>>> wrote:
>>>
>>>> could we have something in type specifications that indicates throw
>>>> case:
>>>>
>>>> -spec f_name( Args ) -> .....; throw(TE | TE1 | ....).
>>>>
>>>> On Wed, Sep 27, 2017 at 11:25 AM, Attila Rajmund Nohl <
>>>> attila.r.nohl@REDACTED> wrote:
>>>>
>>>>> 2017-09-27 11:08 GMT+02:00 Joe Armstrong <erlang@REDACTED>:
>>>>> [...]
>>>>> > This turns out to be very convenient - I read many files
>>>>> > in my programs, so it's nice to know that must_read_file
>>>>> > will print a nice error message and terminate
>>>>> > if I give it a bad filename.
>>>>> >
>>>>> > Note: I can get the program to crash by writing
>>>>> >
>>>>> >    {ok, B} = file:read_file(F)
>>>>> >
>>>>> > But I don't get a nice error message telling me the filename.
>>>>> >
>>>>> > Any takers?
>>>>>
>>>>> My problem with all kinds of very common prefixes is that it breaks
>>>>> function name autocompletion. Or at least makes it harder to use when
>>>>> I have dozens/hundreds/thousands of function names starting with the
>>>>> same 3-5 characters - either I have to type those 3-5 characters all
>>>>> the time plus any more characters to find unique prefix for
>>>>> autocompletion or have to autocomplete twice (one for the may/must
>>>>> difference, one for the actual function name). Eclipse (for Java)
>>>>> helpfully shows the method signature including return value and thrown
>>>>> exceptions - I think this problem should be solved by the IDEs and not
>>>>> by naming conventions.
>>>>> _______________________________________________
>>>>> erlang-questions mailing list
>>>>> erlang-questions@REDACTED
>>>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> erlang-questions mailing list
>>>> erlang-questions@REDACTED
>>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>>
>>>>
>>>
>>>
>>> --
>>> With best regards,
>>>      Roman Galeev,
>>>      +420 702 817 968 <+420%20702%20817%20968>
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
>
>
> --
> With best regards,
>      Roman Galeev,
>      +420 702 817 968 <+420%20702%20817%20968>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170927/0340fdf5/attachment.htm>


More information about the erlang-questions mailing list