lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coding style


From: David Kastrup
Subject: Re: Coding style
Date: Thu, 13 Jan 2011 16:50:20 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Han-Wen Nienhuys <address@hidden> writes:

> On Thu, Jan 13, 2011 at 10:19 AM, David Kastrup <address@hidden> wrote:
>>
>> Hi,
>>
>> in note-collision.cc I read the following:
>>
>>  Direction d = UP;
>>  do
>>    {
>>      vector<Grob*> &clashes (clash_groups[d]);
>>      vector_sort (clashes, Note_column::shift_less);
>>    }
>>  while ((flip (&d)) != UP);
>>
>> Uh, is there any reason not to just write
>>
>>  vector_sort (clash_groups[UP], Note_column::shift_less);
>>  vector_sort (clash_groups[DOWN], Note_column::shift_less);
>>
>> I find it somewhat strange to make a loop for two simple function calls.
>
> In this particular case it may not matter, but the
>
>   while ((flip(&d) != UP)
>
> is a common idiom in the lilypond source code, and you should get used
> to it reading the source code.

It is not a pretty idiom.  Something like

    for (d in [UP,DOWN]) ...

would be much nicer and clearer.  Doesn't C++ have some more useful
idiom for iterators or so?

I think I might even prefer

    while ((flip(&d) == DOWN)

since in that way at least both directions are mentioned.  But the whole
flipping business seems awkward when just two directions are involved.

Something like

    for (d=UP;;d=DOWN) {
      ...
      if (d == DOWN)
         break;
    }

would be somewhat prettier in my book and involve less calculation.

> Overall, I prefer to have programmatic constructs (like this while
> loop) over unrolling loops by hand, and making symmetry of left/right
> and up/down explicit in this way.

Uh, a loop with a single simple function call in it?

-- 
David Kastrup



reply via email to

[Prev in Thread] Current Thread [Next in Thread]