inkporter icon indicating copy to clipboard operation
inkporter copied to clipboard

Please, use English on the source code

Open felipesanches opened this issue 3 years ago • 2 comments

I see that the source code is written with many many comments in a language I do not understand. In general software development is done in English so that a broader number of people can participate.

felipesanches avatar Aug 17 '21 23:08 felipesanches

I thought the same while re-doing the exercise on my own. The only thing I didn't like was having a hanging receive on a branch while the other one may have already finished. The solution I came up with is a little more verbose, but exploiting pattern matching it becomes easier to read and reason about, while keeping the branchy interface the same.

waitBranches(Left, Right, nil, nil) ->
    receive
        {Left, V} -> waitBranches(Left, Right, V, nil);
        {Right, V} -> waitBranches(Left, Right, nil, V)
    end;

waitBranches(Left, Right, LVal, RVal) ->
    receive
        {Left, V} -> {V, RVal};
        {Right, V} -> {LVal, V}
    end.

branchy(F, Left, Right) ->
    receive
        {ask, P} ->
            Left ! {ask, self()},
            Right ! {ask, self()},
            {LVal, RVal} = waitBranches(Left, Right, nil, nil),
            P ! {self(), F(LVal, RVal)}
    end.

Edit: Changed code according to https://github.com/riccardotommasini/ppl/issues/10#issuecomment-356995756

leonardoarcari avatar Jan 11 '18 16:01 leonardoarcari

I like it a lot more, can I include this code in the repository?

riccardotommasini avatar Jan 11 '18 17:01 riccardotommasini

@leonardoarcari you need to swap :) (if I'm getting that right...)

waitBranches(Left, Right, LVal, RVal) ->
    receive
        {Left, V} -> {V, RVal};
        {Right, V} -> {LVal, V}    <-------
    end.

DavideSampietro avatar Jan 11 '18 17:01 DavideSampietro

As for me, no problem with using my code :)

DavideSampietro avatar Jan 11 '18 17:01 DavideSampietro

@DavideSampietro Sure thing! Thanks!

leonardoarcari avatar Jan 11 '18 17:01 leonardoarcari