220 19873 <fed028ba-73b9-47ba-ba71-1a6da1f5212e@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Arthur Tchaikovsky <atch.cpp@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: default arguments
Date: Tue, 18 Aug 2015 02:20:20 -0700 (PDT)
Lines: 322
Approved: news@gmane.org
Message-ID: <fed028ba-73b9-47ba-ba71-1a6da1f5212e@isocpp.org>
References: <ef9c7cbe-e8f1-4196-83bc-11a1c9b2798c@isocpp.org>
 <736eb378-52a4-43ba-b3b5-a73719ba70af@isocpp.org>
 <mqtask$51j$1@ger.gmane.org>
 <86717349-1fce-4247-9372-08eedce4cd30@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_4029_420810057.1439889620237"
X-Trace: ger.gmane.org 1439889625 20312 80.91.229.3 (18 Aug 2015 09:20:25 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 18 Aug 2015 09:20:25 +0000 (UTC)
Cc: bop@gmb.dk
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDL6FI4NYYERBVPRZOXAKGQEIDAYR2Q@isocpp.org Tue Aug 18 11:20:25 2015
Return-path: <std-proposals+bncBDL6FI4NYYERBVPRZOXAKGQEIDAYR2Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f200.google.com ([209.85.213.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDL6FI4NYYERBVPRZOXAKGQEIDAYR2Q@isocpp.org>)
	id 1ZRd4B-0007kC-CN
	for gclcip-std-proposals@m.gmane.org; Tue, 18 Aug 2015 11:20:23 +0200
Original-Received: by igxp17 with SMTP id p17sf171474384igx.3
        for <gclcip-std-proposals@m.gmane.org>; Tue, 18 Aug 2015 02:20:22 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:content-type:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=OIr39DwHJxQECGeAvuNKj6CTw8dQ19ptTWtljz8vi+k=;
        b=XINhc8Xw3WD7ZqX71IhNEgY/0ZRhLSbWzdjR4/AVpCpWkUjV8dbzpxhzVIVtPpCUsK
         bUXuwIcLpvXKhuCUODEzi1Yl/O4SfLdjwHNqgy8Klp6rxmFnlaEf8eeJtSF5/5zHHbto
         xRhy3ACo2B0J1Gq97IqzvWSCGIauuhC8iGYAyJg1hYnXiEq7zwG/oJisjytmZd+pV70W
         FcxJyy44bXbTEC2eiOU6S8Uz7JOt3gZTHGXkNIBBSDQjeiALPgdHHT1qF68hjBC3SC6h
         QCGAoA4lsO4zX7a3uBHyUp4VGfeQ9TNcJYSe/H9lDUwSiCHmjUJ4DU79m739eq32wTfi
         av6A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:content-type:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=OIr39DwHJxQECGeAvuNKj6CTw8dQ19ptTWtljz8vi+k=;
        b=Om0QzmhBhkgTNLXf0VFxO2Q6yPkmmQK+9fXD7N9FSABKlYkolikkrwaa43QSRlNgCZ
         9JBQFH4EMTodx4tLUShhjoSwrHWCUuDXumcCI5cktUhVkKVouE8wm2IztfRmc2ACgleu
         ZjreSacdY1R3wSoOpG+MiWOm+vtImxqt0sVqnr9kgNQzmEFrBPmhlcMbrP0bXC4aBjss
         5Y0vjbIQx7r48XIJEBuPaAS2yOr245S3Ks2GCMmGnhs+GE3A4jGaCzcvQ3KCDcJDFjAt
         1W79LWZ0kD2ieHMEOCwoQyY0EiWaNd1dFC44vJul+IHpXR+hm9t4wJKY/8/9/29FYivI
         +doQ==
X-Gm-Message-State: ALoCoQnMZvZFcp1EeK63kyAKgL5N0qtOqzjKtsGpLXGM1vdH75tQo98ozgQbnz/HtmC/ZBl+l+ys
X-Received: by 10.182.247.2 with SMTP id ya2mr4820287obc.37.1439889622406;
        Tue, 18 Aug 2015 02:20:22 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.103.149 with SMTP id y21ls2610245qge.42.gmail; Tue, 18 Aug
 2015 02:20:21 -0700 (PDT)
X-Received: by 10.140.91.86 with SMTP id y80mr66429qgd.39.1439889621113;
        Tue, 18 Aug 2015 02:20:21 -0700 (PDT)
In-Reply-To: <86717349-1fce-4247-9372-08eedce4cd30@isocpp.org>
X-Original-Sender: atch.cpp@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:19873
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19873>

------=_Part_4029_420810057.1439889620237
Content-Type: multipart/alternative; 
	boundary="----=_Part_4030_460870604.1439889620237"

------=_Part_4030_460870604.1439889620237
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

"I would MUCH rather just rewrite all these constructors"

But did you do it or simply wish that at some point you will find the time=
=20
(and will) to do it, but in the mean time you are still using those "old"=
=20
constructors? Because I also would MUCH rather have C++ cleaned up, yet=20
this will never happen, and I need to use C++ in its current state. What I=
=20
wish is very different to what I have.

And as for you saying that defaulted constructors are antipattern, is that=
=20
a fact or it is simply your opinion?

On Monday, 17 August 2015 23:52:24 UTC+1, Arthur O'Dwyer wrote:
>
> I work on a codebase where this feature would have lots of use-cases,=20
> because we have lots of classes whose constructors have defaulted=20
> parameters:
>
>     C(int buffer_size =3D 1024, int timeout =3D 10, int tries =3D 3) :=20
> buffer_size_(buffer_size), timeout_(timeout), tries_(tries) {}
>
>     auto cptr =3D new C();  // usually the defaults are okay
>     auto c2ptr =3D new C(2048);  // use a bigger buffer
>     auto c3ptr =3D new C(1024, 1);  // use the default buffer size but wi=
th=20
> a shorter timeout
>     auto c4ptr =3D new C(2048, 10, 5);  // testing: bump up the number of=
=20
> tries
>
> It would be marginally more convenient (and refactor-proof) to be able to=
=20
> write
>
>     auto cptr =3D new C();  // usually the defaults are okay
>     auto c2ptr =3D new C(2048);  // use a bigger buffer
>     auto c3ptr =3D new C(default, 1);  // use the default buffer size but=
=20
> with a shorter timeout
>     auto c4ptr =3D new C(2048, default, 5);  // testing: bump up the numb=
er=20
> of tries
>
> However, I consider defaulted parameters in general to be a huge=20
> antipattern, and this constructor pattern in particular to be even worse.
> I would MUCH rather just rewrite all these constructors so that they coul=
d=20
> be used as
>
>     auto cptr =3D new C();  // usually the defaults are okay
>     auto c2ptr =3D new C().withBufferSize(2048);  // use a bigger buffer
>     auto c3ptr =3D new C().withTimeout(1);  // use the default buffer siz=
e=20
> but with a shorter timeout
>     auto c4ptr =3D new C().withBufferSize(2048).withTries(5);  // testing=
:=20
> bump up the number of tries
>
> or
>
>     auto cptr =3D new C();  // usually the defaults are okay
>     auto c2ptr =3D new C(C::BufferSize(2048));  // use a bigger buffer
>     auto c3ptr =3D new C(C::Timeout(1));  // use the default buffer size =
but=20
> with a shorter timeout
>     auto c4ptr =3D new C(C::BufferSize(2048), C::Tries(5));  // testing:=
=20
> bump up the number of tries
>
> or (the most conservative way to rewrite our existing code)
>
>     static constexpr int default_buffer_size =3D 1024;
>     static constexpr int default_timeout =3D 10;
>     static constexpr int default_tries =3D 3;
>     C() : buffer_size_(default_buffer_size), timeout_(default_timeout),=
=20
> tries_(default_tries) {}
>     C(int buffer_size, int timeout, int tries) :=20
> buffer_size_(buffer_size), timeout_(timeout), tries_(tries) {}
>
>     auto cptr =3D new C();  // usually the defaults are okay
>     auto c2ptr =3D new C(2048, C::default_timeout, C::default_tries);  //=
=20
> use a bigger buffer
>     auto c3ptr =3D new C(C::default_buffer_size, 1, C::default_tries);  /=
/=20
> use the default buffer size but with a shorter timeout
>     auto c4ptr =3D new C(2048, C::default_timeout, 5);  // testing: bump =
up=20
> the number of tries
>
> I don't really want to make it *easier* for people to write the "function=
=20
> taking tons of defaulted parameters" antipattern.
> Let's teach people how to avoid the use of defaulted parameters, instead.
>
> =E2=80=93Arthur
>
>
> On Monday, August 17, 2015 at 11:58:41 AM UTC-7, Bo Persson wrote:
>>
>> On 2015-08-17 20:37, Arthur Tchaikovsky wrote:=20
>> > I would really appreciate some feedback from people, or is this=20
>> proposal=20
>> > so uninteresting that there is no point in wasting keyboard on it?=20
>>
>> You might wonder how widely used it will be?=20
>>
>> If not all parameters are of the same type, you can already get some of=
=20
>> the effect with a few overloads:=20
>>
>>      void f(int a =3D 0, string b =3D "1",=20
>>             complex<double> c =3D 2.0, type4 d =3D 3);=20
>>
>>      inline void f(int a, complex<double> c)=20
>>      { f(a, "1", c, 3); }=20
>>
>>      inline void f(string b, complex<double> c)=20
>>      { f(0, b, c, 3); }=20
>>
>> assuming that d is put last because you hardly ever want to change the=
=20
>> default.=20
>>
>> Just saying that you can already do this without a language change.=20
>>
>>
>>     Bo Persson=20
>>
>>
>>
>> >=20
>> > On Saturday, 15 August 2015 17:49:50 UTC+1, Arthur Tchaikovsky wrote:=
=20
>> >=20
>> >     Hi,=20
>> >     Does anyone see helpfulness of such solution:=20
>> >     Having fnc:=20
>> >=20
>> >     void f(int a =3D 0, int b =3D 1, int c =3D 2, int d =3D 3);=20
>> >=20
>> >     I think that it would be nice to be able to say whilst calling it=
=20
>> >     and requiring only some of those args to be non-default:=20
>> >=20
>> >     f(default,2,default,4);=20
>> >=20
>> >     Thoughts?=20
>> >=20
>> >=20
>>
>>
>>

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_4030_460870604.1439889620237
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">&quot;I would MUCH rather just rewrite all these construct=
ors&quot;<br><br>But did you do it or simply wish that at some point you wi=
ll find the time (and will) to do it, but in the mean time you are still us=
ing those &quot;old&quot; constructors? Because I also would MUCH rather ha=
ve C++ cleaned up, yet this will never happen, and I need to use C++ in its=
 current state. What I wish is very different to what I have.<br><br>And as=
 for you saying that defaulted constructors are antipattern, is that a fact=
 or it is simply your opinion?<br><br>On Monday, 17 August 2015 23:52:24 UT=
C+1, Arthur O&#39;Dwyer  wrote:<blockquote class=3D"gmail_quote" style=3D"m=
argin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"=
><div dir=3D"ltr">I work on a codebase where this feature would have lots o=
f use-cases, because we have lots of classes whose constructors have defaul=
ted parameters:<div><br></div><div>=C2=A0 =C2=A0 C(int buffer_size =3D 1024=
, int timeout =3D 10, int tries =3D 3) : buffer_size_(buffer_size), timeout=
_(timeout), tries_(tries) {}</div><div><br></div><div>=C2=A0 =C2=A0 auto cp=
tr =3D new C(); =C2=A0// usually the defaults are okay</div><div>=C2=A0 =C2=
=A0 auto c2ptr =3D new C(2048); =C2=A0// use a bigger buffer<br>=C2=A0 =C2=
=A0 auto c3ptr =3D new C(1024, 1); =C2=A0// use the default buffer size but=
 with a shorter timeout</div><div>=C2=A0 =C2=A0 auto c4ptr =3D new C(2048, =
10, 5); =C2=A0// testing: bump up the number of tries</div><div><br></div><=
div>It would be marginally more convenient (and refactor-proof) to be able =
to write</div><div><br></div><div><div>=C2=A0 =C2=A0 auto cptr =3D new C();=
 =C2=A0// usually the defaults are okay</div><div>=C2=A0 =C2=A0 auto c2ptr =
=3D new C(2048); =C2=A0// use a bigger buffer<br>=C2=A0 =C2=A0 auto c3ptr =
=3D new C(default, 1); =C2=A0// use the default buffer size but with a shor=
ter timeout</div><div>=C2=A0 =C2=A0 auto c4ptr =3D new C(2048,=C2=A0default=
, 5); =C2=A0// testing: bump up the number of tries</div><div><br></div><di=
v>However, I consider defaulted parameters in general to be a huge antipatt=
ern, and this constructor pattern in particular to be even worse.</div><div=
>I would MUCH rather just rewrite all these constructors so that they could=
 be used as</div><div><br></div><div>=C2=A0 =C2=A0 auto cptr =3D new C(); =
=C2=A0// usually the defaults are okay</div><div>=C2=A0 =C2=A0 auto c2ptr =
=3D new C().withBufferSize(2048); =C2=A0// use a bigger buffer<br>=C2=A0 =
=C2=A0 auto c3ptr =3D new C().withTimeout(1); =C2=A0// use the default buff=
er size but with a shorter timeout</div><div>=C2=A0 =C2=A0 auto c4ptr =3D n=
ew C().withBufferSize(2048).<wbr>withTries(5); =C2=A0// testing: bump up th=
e number of tries</div><div><br></div><div>or</div><div><br></div><div><div=
>=C2=A0 =C2=A0 auto cptr =3D new C(); =C2=A0// usually the defaults are oka=
y</div><div>=C2=A0 =C2=A0 auto c2ptr =3D new C(C::BufferSize(2048)); =C2=A0=
// use a bigger buffer<br>=C2=A0 =C2=A0 auto c3ptr =3D new C(C::Timeout(1))=
; =C2=A0// use the default buffer size but with a shorter timeout</div><div=
>=C2=A0 =C2=A0 auto c4ptr =3D new C(C::BufferSize(2048), C::Tries(5)); =C2=
=A0// testing: bump up the number of tries</div></div><div><br></div><div>o=
r (the most conservative way to rewrite our existing code)</div><div><br></=
div><div>=C2=A0 =C2=A0 static constexpr int default_buffer_size =3D 1024;</=
div><div>=C2=A0 =C2=A0 static constexpr int default_timeout =3D 10;</div><d=
iv></div><div>=C2=A0 =C2=A0 static constexpr int default_tries =3D 3;</div>=
<div></div><div>=C2=A0 =C2=A0 C() : buffer_size_(default_buffer_<wbr>size),=
 timeout_(default_timeout), tries_(default_tries) {}<br></div><div><div><di=
v>=C2=A0 =C2=A0 C(int buffer_size, int timeout, int tries) : buffer_size_(b=
uffer_size), timeout_(timeout), tries_(tries) {}</div><div></div></div></di=
v><div><br></div><div>=C2=A0 =C2=A0 auto cptr =3D new C(); =C2=A0// usually=
 the defaults are okay<br></div><div><div>=C2=A0 =C2=A0 auto c2ptr =3D new =
C(2048, C::default_timeout, C::default_tries); =C2=A0// use a bigger buffer=
<br>=C2=A0 =C2=A0 auto c3ptr =3D new C(C::default_buffer_size, 1, C::defaul=
t_tries); =C2=A0// use the default buffer size but with a shorter timeout</=
div><div>=C2=A0 =C2=A0 auto c4ptr =3D new C(2048, C::default_timeout, 5); =
=C2=A0// testing: bump up the number of tries</div></div><div><br></div><di=
v>I don&#39;t really want to make it <i>easier</i> for people to write the =
&quot;function taking tons of defaulted parameters&quot; antipattern.</div>=
<div>Let&#39;s teach people how to avoid the use of defaulted parameters, i=
nstead.</div><div><br></div><div>=E2=80=93Arthur</div><div><br></div><div><=
br></div>On Monday, August 17, 2015 at 11:58:41 AM UTC-7, Bo Persson wrote:=
<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;borde=
r-left:1px #ccc solid;padding-left:1ex">On 2015-08-17 20:37, Arthur Tchaiko=
vsky wrote:
<br>&gt; I would really appreciate some feedback from people, or is this pr=
oposal
<br>&gt; so uninteresting that there is no point in wasting keyboard on it?
<br>
<br>You might wonder how widely used it will be?
<br>
<br>If not all parameters are of the same type, you can already get some of=
=20
<br>the effect with a few overloads:
<br>
<br>=C2=A0 =C2=A0 =C2=A0void f(int a =3D 0, string b =3D &quot;1&quot;,
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 complex&lt;double&gt; c =3D 2=
..0, type4 d =3D 3);
<br>
<br>=C2=A0 =C2=A0 =C2=A0inline void f(int a, complex&lt;double&gt; c)
<br>=C2=A0 =C2=A0 =C2=A0{ f(a, &quot;1&quot;, c, 3); }
<br>
<br>=C2=A0 =C2=A0 =C2=A0inline void f(string b, complex&lt;double&gt; c)
<br>=C2=A0 =C2=A0 =C2=A0{ f(0, b, c, 3); }
<br>
<br>assuming that d is put last because you hardly ever want to change the=
=20
<br>default.
<br>
<br>Just saying that you can already do this without a language change.
<br>
<br>
<br>=C2=A0 =C2=A0 Bo Persson
<br>
<br>
<br>
<br>&gt;
<br>&gt; On Saturday, 15 August 2015 17:49:50 UTC+1, Arthur Tchaikovsky wro=
te:
<br>&gt;
<br>&gt; =C2=A0 =C2=A0 Hi,
<br>&gt; =C2=A0 =C2=A0 Does anyone see helpfulness of such solution:
<br>&gt; =C2=A0 =C2=A0 Having fnc:
<br>&gt;
<br>&gt; =C2=A0 =C2=A0 void f(int a =3D 0, int b =3D 1, int c =3D 2, int d =
=3D 3);
<br>&gt;
<br>&gt; =C2=A0 =C2=A0 I think that it would be nice to be able to say whil=
st calling it
<br>&gt; =C2=A0 =C2=A0 and requiring only some of those args to be non-defa=
ult:
<br>&gt;
<br>&gt; =C2=A0 =C2=A0 f(default,2,default,4);
<br>&gt;
<br>&gt; =C2=A0 =C2=A0 Thoughts?
<br>&gt;
<br>&gt;
<br>
<br>
<br></blockquote></div></div></blockquote></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_4030_460870604.1439889620237--
------=_Part_4029_420810057.1439889620237--

.
