220 32048 <57ddf392-ae57-bfd2-1ae6-15da6fce5aa9@scylladb.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Avi Kivity <avi@scylladb.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Non-last default arguments
Date: Fri, 7 Apr 2017 12:36:25 +0300
Lines: 311
Approved: news@gmane.org
Message-ID: <57ddf392-ae57-bfd2-1ae6-15da6fce5aa9@scylladb.com>
References: <91d734b5-d1f2-773a-b5c2-3b96696a6f0f@scylladb.com>
 <CAFdMc-2Q8FyP-qqJCT-zDj4kfrqQ89G4qdWuWtVJAzDvFuOZ5w@mail.gmail.com>
 <a39f277a-549f-4b4a-881b-09fd1cf4087e@isocpp.org>
 <23242c11-a20b-9dfe-42fc-7a1ae3195849@scylladb.com>
 <6ee7b168-7b23-4368-a587-1f4042903db9@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------13372B8BD8DCF0F697C29281"
X-Trace: blaine.gmane.org 1491557796 8125 195.159.176.226 (7 Apr 2017 09:36:36 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 7 Apr 2017 09:36:36 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.8.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDHJFOWD7YCRBIN3TXDQKGQEV7D6SIA@isocpp.org Fri Apr 07 11:36:29 2017
Return-path: <std-proposals+bncBDHJFOWD7YCRBIN3TXDQKGQEV7D6SIA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f72.google.com ([209.85.215.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDHJFOWD7YCRBIN3TXDQKGQEV7D6SIA@isocpp.org>)
	id 1cwQJg-0001Hw-Tf
	for gclcip-std-proposals@m.gmane.org; Fri, 07 Apr 2017 11:36:28 +0200
Original-Received: by mail-lf0-f72.google.com with SMTP id f66sf11603595lfe.23
        for <gclcip-std-proposals@m.gmane.org>; Fri, 07 Apr 2017 02:36:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:x-original-sender:x-original-authentication-results
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=9/PpGhs0wWvKo0vCg0eQOZpDiw647pRGw3lQBfF8C+g=;
        b=wH2in7Dw65QeN8eAdL/aEjkvCJ8opTK2Cbd9sPVK71Ec8JuGjq0pkmDUDyttHcSb0T
         zhmNp/d6+Y7SPtzIu8+44BNPkmJsU/x6xEZmqSczk4yqyt6UwrYTEoTnOhgEh1GEAwlg
         MTvHcqSF0QuY4Zmi2qekFLr7cTWK6M8I6HE/7ySUSMXOh5dRCbWhgxEXKzhzm8yh09Yc
         MUgO5VYAD3IyPU5VoQmWNYTWDOBXXl+ihVEUzdRBx/oIUo996DK0RrxPaJLGv2nWSYCS
         AFi30J5XGRgkLTlaquMEOc1DuYsL+hXPGtoE2KNT+N5FTWTxKj3pzTC20IPySrZhU0Z5
         oVZQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=9/PpGhs0wWvKo0vCg0eQOZpDiw647pRGw3lQBfF8C+g=;
        b=ucrvdZAB4wZybdWo3nGmod+xFQwFwl1CywnpxMeka9gq1ogvdNK/O1seLpavbY8M+I
         +VCXtQqDjyEwUHK9Nj+w5ztdnL2vUNRVfrDu6Sy0wyx4w8Hq06bSIkvfHrPGOPYZJlUT
         x3Qq16I0Gsb43Tg2U3y8pUvlbylcxS92t0YQ0VNDTdeFNXX3gWulCOgMFJFdEvqAAuIy
         82qBnjidk0T5xi3kk/9Ek0lWDf8pLOZRazH1dvneSi0DecVL9y3DMmr5V06v+IJ/UWpg
         vfFrDy9PDK/JWjeQZuBWVZZmcG7jEHlDZKwQx5xQ4jt9pMOMYIjxxUMtQ8BYEXX/znaN
         rfLQ==
X-Gm-Message-State: AN3rC/7Pv2jVgrU9pGpVol3HuSVfkFyy0+ib8izyGwb8OIuIa62ZSXbp6sGr4HMyl3Vv3Q==
X-Received: by 10.25.215.220 with SMTP id q89mr452687lfi.28.1491557794941;
        Fri, 07 Apr 2017 02:36:34 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.45.135 with SMTP id t129ls93859wmt.20.gmail; Fri, 07 Apr
 2017 02:36:33 -0700 (PDT)
X-Received: by 10.223.147.98 with SMTP id 89mr31153063wro.99.1491557793322;
        Fri, 07 Apr 2017 02:36:33 -0700 (PDT)
Original-Received: from mail-wr0-x230.google.com (mail-wr0-x230.google.com. [2a00:1450:400c:c0c::230])
        by mx.google.com with ESMTPS id v124si7378218wmd.89.2017.04.07.02.36.33
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 07 Apr 2017 02:36:33 -0700 (PDT)
Received-SPF: pass (google.com: domain of avi@scylladb.com designates 2a00:1450:400c:c0c::230 as permitted sender) client-ip=2a00:1450:400c:c0c::230;
Original-Received: by mail-wr0-x230.google.com with SMTP id c55so25455283wrc.3
        for <std-proposals@isocpp.org>; Fri, 07 Apr 2017 02:36:33 -0700 (PDT)
X-Received: by 10.223.134.203 with SMTP id 11mr2259040wry.149.1491557792958;
        Fri, 07 Apr 2017 02:36:32 -0700 (PDT)
Original-Received: from [10.0.0.3] (bzq-79-176-149-103.red.bezeqint.net. [79.176.149.103])
        by smtp.googlemail.com with ESMTPSA id y66sm5303375wrb.39.2017.04.07.02.36.31
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 07 Apr 2017 02:36:31 -0700 (PDT)
In-Reply-To: <6ee7b168-7b23-4368-a587-1f4042903db9@isocpp.org>
X-Original-Sender: avi@scylladb.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@scylladb-com.20150623.gappssmtp.com;       spf=pass (google.com:
 domain of avi@scylladb.com designates 2a00:1450:400c:c0c::230 as permitted
 sender) smtp.mailfrom=avi@scylladb.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:32048
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/32048>

This is a multi-part message in MIME format.
--------------13372B8BD8DCF0F697C29281
Content-Type: text/plain; charset=UTF-8; format=flowed

On 04/06/2017 07:44 PM, Nicol Bolas wrote:
>
>
> On Thursday, April 6, 2017 at 12:28:33 PM UTC-4, Avi Kivity wrote:
>
>
>
>     On 04/06/2017 06:26 PM, Nicol Bolas wrote:
>>     On Thursday, April 6, 2017 at 11:17:42 AM UTC-4, dgutson wrote:
>>
>>         see the date:
>>         http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1466.pdf
>>         <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1466.pdf>
>>
>>
>>     I'm with Stroustrup: "Nahh...don't complicate default parameters.
>>     We have overloading instead."
>     How can I overload f(int = 1, int = 2, int = 3, int = 4) to allow
>     any combination of parameters to be overloaded?
>
>     Named arguments would be better though, but I understand that's
>     dead (and why).
>
>
> But it's not dead. Designated initializers will apparently exist in 
> C++20, which gives you the effective equivalent of named parameters:
>
> |
> structf_args
> {
> inta =1;intb =2;intc =3;intd =4;
> };
>
> voidf(f_args args);
>
> f({.b =1});
> |
>
> Equally importantly... why do you /need/ to give people all of this 
> complexity? If your function has that many arguments, and that many of 
> them have default values, and none of those parameters are more likely 
> to be defaulted than others, then it seems very likely that your 
> function is doing too much work or otherwise taking too many parameters.

Sometimes functions are indeed complicated, and sometimes they evolve 
this way.  I hope C++ is not meant for perfect software only.

>
> Furthermore, can you provide a real-world example of a case where the 
> user using this feature would make the code less complex? And by that, 
> I mean less complex than just living with the limitation, not less 
> complex than jumping through a bunch of hoops to enforce it. I have a 
> hard time reading`some_func(default, value, value, default, value)` 
> and understanding what that function is doing.

I too prefer a struct for passing large number of configuration items.  
If we have designated initializers, then that's a superior solution to 
the problem.


The typical pattern I see

   start with a constructor with a few (maybe no) parameters
   grow parameters overtime, defaulting them to preserve compatibility
   give up in disgust and replace with a config struct, adding much 
boilerplate to call sites

Designated initializers aren't perfect for this, but they're pretty good 
(real named arguments would be better).

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/57ddf392-ae57-bfd2-1ae6-15da6fce5aa9%40scylladb.com.

--------------13372B8BD8DCF0F697C29281
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">On 04/06/2017 07:44 PM, Nicol Bolas
      wrote:<br>
    </div>
    <blockquote
      cite=3D"mid:6ee7b168-7b23-4368-a587-1f4042903db9@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr"><br>
        <br>
        On Thursday, April 6, 2017 at 12:28:33 PM UTC-4, Avi Kivity
        wrote:
        <blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
          0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
          <div bgcolor=3D"#FFFFFF" text=3D"#000000">
            <p><br>
            </p>
            <br>
            <div>On 04/06/2017 06:26 PM, Nicol Bolas wrote:<br>
            </div>
            <blockquote type=3D"cite">
              <div dir=3D"ltr">On Thursday, April 6, 2017 at 11:17:42 AM
                UTC-4, dgutson wrote:
                <blockquote class=3D"gmail_quote"
                  style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc
                  solid;padding-left:1ex">
                  <div dir=3D"ltr">see the date: <a
                      moz-do-not-send=3D"true"
                      href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/p=
apers/2003/n1466.pdf"
                      rel=3D"nofollow" target=3D"_blank"
onmousedown=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww=
..open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2003%2Fn1466.pdf\x26sa=
\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6n-B7857cuj_lMr4yqOp36CJ-rg';return
                      true;"
onclick=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.ope=
n-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2003%2Fn1466.pdf\x26sa\x3d=
D\x26sntz\x3d1\x26usg\x3dAFQjCNH6n-B7857cuj_lMr4yqOp36CJ-rg';return
                      true;">http://www.open-std.org/jtc1/<wbr>sc22/wg21/do=
cs/papers/2003/<wbr>n1466.pdf</a></div>
                </blockquote>
                <div><br>
                  I'm with Stroustrup: "Nahh...don't complicate default
                  parameters. We have overloading instead."</div>
              </div>
            </blockquote>
            How can I overload f(int =3D 1, int =3D 2, int =3D 3, int =3D 4=
) to
            allow any combination of parameters to be overloaded?<br>
            <br>
            Named arguments would be better though, but I understand
            that's dead (and why).<br>
          </div>
        </blockquote>
        <div><br>
          But it's not dead. Designated initializers will apparently
          exist in C++20, which gives you the effective equivalent of
          named parameters:<br>
          <br>
          <div style=3D"background-color: rgb(250, 250, 250);
            border-color: rgb(187, 187, 187); border-style: solid;
            border-width: 1px; overflow-wrap: break-word;"
            class=3D"prettyprint"><code class=3D"prettyprint">
              <div class=3D"subprettyprint"><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">struct</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  f_args<br>
                </span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">{</span><span style=3D"color=
:
                  #000;" class=3D"styled-by-prettify"><br>
                  =C2=A0 </span><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">int</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> a </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">1</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> b </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">2</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> c </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">3</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> d </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">4</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                </span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">};</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                  <br>
                </span><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">void</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> f</s=
pan><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">f_arg=
s
                  args</span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">);</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                  <br>
                  f</span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">({.</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">b </s=
pan><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">1</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">});</=
span></div>
            </code></div>
          <br>
          Equally importantly... why do you <i>need</i> to give people
          all of this complexity? If your function has that many
          arguments, and that many of them have default values, and none
          of those parameters are more likely to be defaulted than
          others, then it seems very likely that your function is doing
          too much work or otherwise taking too many parameters.<br>
        </div>
      </div>
    </blockquote>
    <br>
    Sometimes functions are indeed complicated, and sometimes they
    evolve this way.=C2=A0 I hope C++ is not meant for perfect software onl=
y.<br>
    <br>
    <blockquote
      cite=3D"mid:6ee7b168-7b23-4368-a587-1f4042903db9@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr">
        <div><br>
          Furthermore, can you provide a real-world example of a case
          where the user using this feature would make the code less
          complex? And by that, I mean less complex than just living
          with the limitation, not less complex than jumping through a
          bunch of hoops to enforce it. I have a hard time
          reading`some_func(default, value, value, default, value)` and
          understanding what that function is doing.<br>
        </div>
      </div>
    </blockquote>
    <br>
    I too prefer a struct for passing large number of configuration
    items.=C2=A0 If we have designated initializers, then that's a superior
    solution to the problem.<br>
    <br>
    <br>
    The typical pattern I see<br>
    <br>
    =C2=A0 start with a constructor with a few (maybe no) parameters<br>
    =C2=A0 grow parameters overtime, defaulting them to preserve
    compatibility<br>
    =C2=A0 give up in disgust and replace with a config struct, adding much
    boilerplate to call sites<br>
    <br>
    Designated initializers aren't perfect for this, but they're pretty
    good (real named arguments would be better).<br>
    <br>
  </body>
</html>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/57ddf392-ae57-bfd2-1ae6-15da6fce5aa9%=
40scylladb.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.googl=
e.com/a/isocpp.org/d/msgid/std-proposals/57ddf392-ae57-bfd2-1ae6-15da6fce5a=
a9%40scylladb.com</a>.<br />

--------------13372B8BD8DCF0F697C29281--

.
