[erlang-questions] Must and May convention
Thu Sep 28 17:01:01 CEST 2017
On 09/28/2017 04:14 PM, Joe Armstrong wrote:
>> For example:
>> test2(F) ->
>> F = parse(tokenize(ok(file:read_file()))).
>> This exhibits no real differences because there is no underlying rule
>> applied other than simple composition.
> My problem with the above is I almost never write like this
> In my head I'm thinking "first you read the file then you tokenize it
> then you parse it"
I wonder how a native speaker of a RTL language would feel about this?
Perhaps it would make a lot more sense for them.
Personally I don't have an issue about the order in these cases, the
only times I do worry about order is when doing arithmetic or boolean
operations (because I can never remember precedence rules, so I put
parents around everything). So a simplified example like the above feels
perfectly natural. A more complex example with many arguments could of
course be harder to read. Which leads to...
> So pipes or breaking the code line by line with temporary variables
> is fine by me. Adding temporary variables is also nice because you
> can print them when things go wrong.
I think breaking up has two more important properties than order.
First, they make expressions shorter. Short expressions are easy to read
and to understand.
Second, they make the operations independent. This makes the block
easier to read and to update.
These two properties are not provided by pipes, you still have a big
expression, you just changed the written order. Worse, this only works
if your subject is always the first argument, so you end up having to do
it the traditional way in some cases anyway. (Unless that changed.)
More information about the erlang-questions