C++ Logo

std-proposals

Advanced search

Re: Making parameter names clearer than func(true, false);

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Sat, 6 Jul 2019 11:05:47 -0400
On Sat, Jul 6, 2019 at 9:13 AM Jonny Grant via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hello
> My first post!
>
> *Parameter Names*
>
> Don't you just hate it when you're reading code that looks like this and
> no idea what those parameters are ?
>
> func(true, false);
>
> This is the function declaration - but it's a pain to go and find that:
> void func(bool debug, bool log);
>
> With this proposal, allowing inclusion of the parameter names makes it
> clear:
> func(debug=true, log=false);
>

Well, that's not much of a "proposal" at this stage. ;)
Think about what your proposal should do with

    void func(int debug, int log);
    int main() {
        bool debug = false;
        func(debug=true, log=false);
    }

And think about what your proposal should do with

    void func(int debug, int log); // overloaded
    void func(bool log2, bool debug2); // overloaded
    int main() {
        func(debug=true, log=false);
    }

P.S.: I hadn't read Axel Naumann's P0671 "Self-Explanatory Function
Arguments" before, but it strikes me as a pretty good approach. What
problems do you see with P0671's approach, and how does your proposed
proposal fix them?

> http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0671r2.html
>

–Arthur

Received on 2019-07-06 10:07:51