lmi
[Top][All Lists]
Advanced

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

Re: [lmi] [lmi-commits] master 39f6c8c 2/2: Refactor, adding an argumen


From: Vadim Zeitlin
Subject: Re: [lmi] [lmi-commits] master 39f6c8c 2/2: Refactor, adding an argument to years_and_months_since()
Date: Thu, 22 Jun 2017 15:14:44 +0200

On Thu, 22 Jun 2017 07:14:02 -0400 (EDT) Greg Chicares <address@hidden> wrote:

GC> branch: master
GC> commit 39f6c8c50f42e74105bf28aa4e2d50994e2bf41b
GC> Author: Gregory W. Chicares <address@hidden>
GC> Commit: Gregory W. Chicares <address@hidden>
GC> 
GC>     Refactor, adding an argument to years_and_months_since()
GC>     
GC>     The new argument is specified as 'true' in all cases and ignored for
GC>     now. Soon, it will affect behavior and be specified differently in
GC>     certain cases.
GC> ---
...
GC>      BOOST_TEST_THROW
GC> -        (years_and_months_since(base_date, other_date)
GC> +        (years_and_months_since(base_date, other_date, true)

 For many years I've been on a crusade against boolean arguments, so let me
try to convince you of their evil: the argument is basically just that the
line above is incomprehensible as you have no idea about what does this
"true" mean. Of course, you can bring up the years_and_months_since()
function declaration in your IDE/editor/mind (this depends on whichever
tool is the most efficient for you), but even if it's very easy for you to
do so, wouldn't it better if you didn't have to do it?

 And this can be easily achieved by just using an enum with clear names
instead of bool. If you saw

        years_and_months_since(base_date, other_date, annuity_curtate)

it would be immediately clear and it would require just a few more lines
to declare this enum with its 2 elements. IMO it's well worth it except for
private functions which are only used in the code immediately next to their
declaration.

 I don't know if I've convinced you, but I wanted to at least try. As I
read much more code than I write, I hate boolean parameters with a passion.

 Regards,
VZ


reply via email to

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