220 4096 <7c79ca05-607f-40e8-bd51-467363f007ac@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Default values in middle parameters in a function
Date: Mon, 29 Apr 2013 23:43:50 -0700 (PDT)
Lines: 156
Approved: news@gmane.org
Message-ID: <7c79ca05-607f-40e8-bd51-467363f007ac@isocpp.org>
References: <25d51458-9a2e-4607-9b1a-9d2a7be8df4e@isocpp.org>
 <CAGqM8fYDgZbfH6dugPnLqYvwZhSeVvC+gMVLLLx3OzYBmYByTg@mail.gmail.com>
 <CAE1+XsZWWbKwX+vJc7VQUjyRXXvmJePofKy2CP8+3ERRtTYrYw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_1230_30249893.1367304230614"
X-Trace: ger.gmane.org 1367304238 18323 80.91.229.3 (30 Apr 2013 06:43:58 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 30 Apr 2013 06:43:58 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBKWQ7WFQKGQE5LINDBA@isocpp.org Tue Apr 30 08:43:55 2013
Return-path: <std-proposals+bncBCEKFTV6ZUMBBKWQ7WFQKGQE5LINDBA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f71.google.com ([209.85.219.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBKWQ7WFQKGQE5LINDBA@isocpp.org>)
	id 1UX4I7-0004lT-Gf
	for gclcip-std-proposals@m.gmane.org; Tue, 30 Apr 2013 08:43:55 +0200
Original-Received: by mail-oa0-f71.google.com with SMTP id o17sf1148315oag.10
        for <gclcip-std-proposals@m.gmane.org>; Mon, 29 Apr 2013 23:43:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-received:x-beenthere:x-received:date:from:to:message-id
         :in-reply-to:references:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-google-group-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=b0g87Bm7ftNKHTIGBnaIcKjjn+3SO11wIghl6V43qrI=;
        b=LWr30bhbCRs4gbcYxavtB4SWKJfcDfTx7R3p+yTMLP/bumwkGEEC2Avr1Y3OM+fzpi
         hNZdf+16AIWpO2Hql03fKW6O9Q5nmFrnqJuozHp8UwV4typJUK7cJPApZ6pMKnBgtVFs
         yk6I1kZuS+jJhDLQ1fadLRrYBqEX3HObSfS5mOxf6IAaoa1muPvk55LtrJItCe+mTG9k
         nWXRtMXHREJUILlQL8GyHs4n3gp03K41as8GiPmct5/m3QIsbKvZ1u3PnAiAVud2+Fdb
         u7go2BTJHALnMazFd8EFEeXsnnUu73CHw4rWm9J6ApPk+TywXFkrOKlE3r5yfdtlDz9s
         f3Ug==
X-Received: by 10.182.243.233 with SMTP id xb9mr741786obc.1.1367304234509;
        Mon, 29 Apr 2013 23:43:54 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.38.170 with SMTP id h10ls15088obk.54.gmail; Mon, 29 Apr
 2013 23:43:52 -0700 (PDT)
X-Received: by 10.182.29.8 with SMTP id f8mr73483obh.39.1367304232095;
        Mon, 29 Apr 2013 23:43:52 -0700 (PDT)
In-Reply-To: <CAE1+XsZWWbKwX+vJc7VQUjyRXXvmJePofKy2CP8+3ERRtTYrYw@mail.gmail.com>
X-Original-Sender: jmckesson@gmail.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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:4096
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4096>

------=_Part_1230_30249893.1367304230614
Content-Type: text/plain; charset=ISO-8859-1

On Monday, April 29, 2013 10:32:40 PM UTC-7, Hariharan Subramanian wrote:
>
> Default parameters can vary between translation units, which is
>> not good for code clarity.  They can also cause address-of-function
>> problems and binary compatibility problems.  An overload set is a
>> significantly better approach to the problems that default parameters
>> solve.  I would rather the user wrote function overloads to handle
>> the various cases.  Mostly, you can do this in an API-compatible
>> manner.  So, rather than extend a flawed feature, I would rather say
>> "do not do that".
>>
>
> Default parameters are a reality and used extensively. Instead of making a 
> "flawed feature" difficult to work with it makes this "flawed feature" 
> easier to work with. 
>

Personally, I don't think that default parameters are a "flawed feature". 
That being said, the flaws discussed are *not* resolved by your suggestion.

Default parameters solve a simple, very specific problem. Function 
overloading solves a larger, more general problem. I like that we have 
both. And I think that the problem that you intend to solve, with some kind 
of "default" parameter, is best solved with the larger, more general 
solution.

Also, with `optional`:

void foo(int param, optional<type1> value1, optional<type2> value2) {
  type1 val1 = value1.value_or(a1);
  type2 val2 = value2.value_or(a2);
  //implementation
}

void usefoo() {
       foo(0, nullopt, b2);
}

That seems to take care of the problem.

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.



------=_Part_1230_30249893.1367304230614
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Monday, April 29, 2013 10:32:40 PM UTC-7, Hariharan Subramanian wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=
=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex">Default parameters can vary=
 between translation units, which is<br>

not good for code clarity. &nbsp;They can also cause address-of-function<br=
>
problems and binary compatibility problems. &nbsp;An overload set is a<br>
significantly better approach to the problems that default parameters<br>
solve. &nbsp;I would rather the user wrote function overloads to handle<br>
the various cases. &nbsp;Mostly, you can do this in an API-compatible<br>
manner. &nbsp;So, rather than extend a flawed feature, I would rather say<b=
r>
"do not do that".<br></blockquote><div><br></div><div>Default parameters ar=
e a reality and used extensively. Instead of making a "flawed feature" diff=
icult to work with it makes this "flawed feature" easier to work with.&nbsp=
;</div></div></div></div></blockquote><div><br>Personally, I don't think th=
at default parameters are a "flawed feature". That being said, the flaws di=
scussed are <i>not</i> resolved by your suggestion.<br><br>Default paramete=
rs solve a simple, very specific problem. Function overloading solves a lar=
ger, more general problem. I like that we have both. And I think that the p=
roblem that you intend to solve, with some kind of "default" parameter, is =
best solved with the larger, more general solution.<br><br>Also, with `opti=
onal`:<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(250=
, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-=
width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> fo=
o</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> param</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> optional</span><span style=3D"color:=
 #080;" class=3D"styled-by-prettify">&lt;type1&gt;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> value1</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> optional</span><span style=3D"color: #080;" cl=
ass=3D"styled-by-prettify">&lt;type2&gt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> value2</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>&nbsp; type1 val1 </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> value1</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">value_o=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">a1</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; type2 val2 </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> value2</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">value_or</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">a2</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>&nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-p=
rettify">//implementation</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">vo=
id</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> usefoo<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp;foo</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
 style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> nullopt</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> b2</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span></div></code></div><br>That seems to take care of the problem.<br></di=
v>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1230_30249893.1367304230614--

.
