On Fri, Apr 26, 2013 at 10:54 AM, Vincent van Ravesteijn <v...@lyx.org> wrote:
> Op 26-4-2013 4:05, Scott Kostyshak schreef:
>
>> On Thu, Apr 25, 2013 at 4:49 PM, Vincent van Ravesteijn <v...@lyx.org>
>> wrote:
>>>
>>> Op 1-4-2013 6:07, Scott Kostyshak schreef:
>>>>
>>>> I think this is something I need to get used to: I would not have
>>>> thought that this duplication of code (e.g. reparsing the string in
>>>> the same way) was a good solution but I do see this a lot in C++ so
>>>> it's something I need learn.
>>>
>>>
>>> What do you mean ?
>>
>> Checking whether a debug flag is valid and then setting that debug
>> flag both involve looping through all the debug flags. When initially
>> looking at this, the most natural thing seemed to me that there should
>> be only one loop. But I think this separation of validation and
>> processing is common in C++ and that I should learn to not worry about
>> looping twice instead of once. Especially for such a small vector,
>> this does not have any real performance issue.
>>
>> Besides performance though it still seems to me that the code could be
>> more simple if there were just one loop. Is there a reason why it
>> would be bad in this case to have one loop and throw an exception if a
>> debug flag does not exist? Would it be reasonable to do a try/catch
>> around lyxerr.setLevel(Debug::value(arg)) and obviate the need for
>> Debug::isKnownValue(tmp) ?
>>
>
> I hate throwing exceptions.

Why? I have little experience with them so I don't know their
disadvantages. If you can point me to a discussion of their faults,
that would be great. I found some results by googling "don't use
exceptions c++" but I thought that you might have something in mind
that's specific for this case. From what I remember, the authors of
the "Professional C++" book are in love with exceptions. I have no
idea how highly/lowly regarded their opinions are.

>What is not simple about what I proposed ?

"simple" wasn't the correct word. It is simple. It's just not what I
would have first imagined because it duplicates code. What if how we
loop through debug flags changes or there is a bug that is found in
one of the loops? The other loop doesn't automatically change. Again,
I'm not saying this is bad. I'm just trying to learn that this is not
bad so that next time I come across such a problem I will recognize
what the correct approach is.

> You shouldn't be worrying about performance in this kind of UI cases. It
> really doesn't care to do 40 checks compared to 20.  The same holds for the
> issue in another thread about disabling controls on every character entered.
> In that box you typically enter a few characters, so a few extra loops are
> really not an issue.. never.

I'm now convinced that performance is not an issue. I'm less convinced
that readability and maintainability are better than using exceptions.
I trust that you're right (and I see that what you're recommending
here is common in many other parts of the code). I'm just trying to
figure out why.

What do you think of the most recent patch I posted? I think I
implemented the important part of what you proposed.
(http://permalink.gmane.org/gmane.editors.lyx.devel/145483)

Thanks for the help,

Scott

Reply via email to