[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] Why 'continue' here?
From: |
Greg Chicares |
Subject: |
Re: [lmi] Why 'continue' here? |
Date: |
Wed, 8 Aug 2018 16:19:49 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
On 2018-08-07 22:32, Vadim Zeitlin wrote:
> On Tue, 7 Aug 2018 20:56:04 +0000 Greg Chicares <address@hidden> wrote:
[...]
> 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.
Thanks, I'm about to push something like that.
I don't share your positive view of the "if statement with initializer"
though. It looks like they've reinvented C's comma operator.