[erlang-questions] Request feedback on example project

zxq9 <>
Wed Feb 3 08:10:06 CET 2016


On 2016年2月3日 水曜日 07:33:57 you wrote:
> On Wed, Feb 3, 2016 at 7:00 AM, zxq9 <> wrote:
> 
> > I would like feedback from new and old Erlangers in terms of readability,
> > documentation, what is easy to understand, what is hard to understand, etc.
> > My goal is to develop a style plain enough that a utility application just
> > above the threshold of clear triviality (like a UUID utility) is mostly
> > understandable even to someone new to Erlang.
> 
> After a quick look, I have only one nit to pick
> (and it is of course a matter of taste):
> 
> You wrote:
> 
> when V > 0 andalso V < 6 ->
> 
> I would write it like:
> 
> when 0 < V, V < 6 ->
> 
> First, by putting the variable V in the middle it
> easier to see that the guard is a range test
> and not any two unrelated conditions. Second,
> I never use 'andalso' when a simple ',' would do.

Hi Björn!

This particular spot actually made me pause for a moment.

There should never be a chance where 0 > V because V is
extracted from a match on bits:

    version({uuid, <<_:48, V:4, _:12, 2:2, _:62>>})
            when V > 0 andalso V < 6 ->

Therefore the following should be just as safe:

    version({uuid, <<_:48, V:4, _:12, 2:2, _:62>>})
            when V < 6 ->

But...

1- How obvious is this for someone new to Erlang?
2- If they are seeing this then they are reading the source; would a comment
   not be more understandable and leave the code more correct?

This is certainly a nitpick -- but its the sort of tiny reader-focused
nitpick I'm looking for.

Thanks!
-Craig


More information about the erlang-questions mailing list