lmi
[Top][All Lists]
Advanced

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

Re: [lmi] Why 'continue' here?


From: Vadim Zeitlin
Subject: Re: [lmi] Why 'continue' here?
Date: Wed, 8 Aug 2018 00:32:39 +0200

On Tue, 7 Aug 2018 20:56:04 +0000 Greg Chicares <address@hidden> wrote:

GC> Vadim--This is not urgent, because I believe I've figured it out
GC> below. When you have time...can you remember the reason for this
GC> 'continue' in numeric_summary_table_cell::render_or_measure()
GC> on the original 'vz-no-xslfo' branch?

 I don't really remember it, but rereading the code now I'm pretty sure the
intention was to handle this case specially just because it isn't supported
by the generic mechanism (i.e. HTML interpolator) directly. As for the use
of "continue", it seems to be consistent with the other couple of uses of
this keyword in this function just above, although it could, of course, be
argued that we don't need to be consistent between different loops.

[...]
GC> and I'm guessing that therefore the intention of the code:
GC> 
GC>   for(all columns)
GC>       {
GC>       if(special_condition)
GC>           {
GC>           output = special_age_70_string;
GC>           continue;
GC>           }
GC>       output = normal_output;
GC>       }
GC> 
GC> is simply this:
GC> 
GC>   for(all columns)
GC>       {
GC>       output = normal_output;
GC>       if(special_condition)
GC>           output = special_age_70_string;
GC>       }

 I'd rather write it like this (this is pseudo code but uses convenient
C++17 "if statement with initializer" feature which allows to write it more
clearly and concisely than without it):

        for(all columns)
            {
            string out;
            if(is_last_row && j == column_policy_year)
                out = "Age last";
            else if(auto const& var = columns[j].variable_name; !var.empty())
                out = interpolate_html.evaluate(var, year - 1);
            //else: leave empty for separator columns

            output_values[j] = out;

            ... same code as now ...
            }

This seems more clear to me than overwriting the output as it explicitly
shows that there are 3 different cases.

GC> I'll rewrite it that way, because at the bottom of that for-loop
GC> I want to add some code that should be executed on every pass.

 Yes, this is a perfectly good reason to get rid of "continue", but I think
initializing the variable and immediately overwriting it as written above
wouldn't be the best alternative.

 Regards,
VZ


reply via email to

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