220 34167 <ff2ceb41-caca-4659-9a7d-4da9c2046810@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Idea: Extension of structured bindings to
 definition of structs
Date: Sun, 27 Aug 2017 07:11:03 -0700 (PDT)
Lines: 192
Approved: news@gmane.org
Message-ID: <ff2ceb41-caca-4659-9a7d-4da9c2046810@isocpp.org>
References: <59dcbbbc-c536-4b7b-9c88-0638fb0cd58a@technion.ac.il> <7b9bf263-d3ca-42bf-aed6-4c7606782a28@isocpp.org>
 <1762295.OciJaA9sdk@tjmaciei-mobl1>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_5391_811571578.1503843063950"
X-Trace: blaine.gmane.org 1503843082 30841 195.159.176.226 (27 Aug 2017 14:11:22 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 27 Aug 2017 14:11:22 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBB6NFRPGQKGQEVI4V6ZA@isocpp.org Sun Aug 27 16:11:16 2017
Return-path: <std-proposals+bncBCEKFTV6ZUMBB6NFRPGQKGQEVI4V6ZA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f71.google.com ([74.125.83.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBB6NFRPGQKGQEVI4V6ZA@isocpp.org>)
	id 1dlyHE-0006sY-EF
	for gclcip-std-proposals@m.gmane.org; Sun, 27 Aug 2017 16:11:00 +0200
Original-Received: by mail-pg0-f71.google.com with SMTP id q16sf31715706pgc.7
        for <gclcip-std-proposals@m.gmane.org>; Sun, 27 Aug 2017 07:11:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=temrFl0g15Mh7gaXJT5lARid6I3gOJEEK2kuMTHX2S8=;
        b=x9boozHF//JjHzTOg7fZQT3/qv9P6RcM5WRAQpqqaiogBrL5+MCoHhrrJcSmui+Q67
         FaJL8OJQqy1DR4sDiGabPfm3lCnYs8CAJ3uyWOHqdlY8f/iD450+Yp2nzwFw4zNKfqeM
         wSUvWhhJKzpHOdknWSnQ+fPKVfoQCrcxwW0+5FjmhTnWXD0vrqg25h0Umdbvxb3tzawJ
         3o5bBDTLcUxF2TCNDLY6jlr2m0t6mwyObJNu5/pJiTa4W/ekXiWvPU3juic3d2KAwoTb
         LoT95DXnX9FljD9D2Oh9TJnEKgnRoZAxk2qsei/CEQR1UDuq6yqUZdoApeopscsybtMo
         /UfA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=temrFl0g15Mh7gaXJT5lARid6I3gOJEEK2kuMTHX2S8=;
        b=aaVDPcQLor3c8Xw60q6OaY5X03WsJOtNi8tU2lfBNGjQuJl5gzBLYkj+ZHX35SyYX8
         ++6XbQvoUF5yaTnzfggsBaoMJFzmDQ4USk1kBsYt77eovoiZ6iakHlJ2Z7LBxIP9oVDa
         GhuLIxP2xg0Mnw9gf18CGBciAgFuFcVj2XVWID8OhswFvGkycVd5bBgp7jyTnPZP1cuo
         G8r3Jm8ARgyBV4kvfJIvMTqzsszDLZpgYt5RW/AaWwxfjCUtwX4WrQv2rw6vjdnfN4C2
         ESqwNO3K0/R15+86WshrV8U1FSRWF+9MBfgqUV9W4nltukbiass0RMTBIEcq4ZgFTIKt
         QZsg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version: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=temrFl0g15Mh7gaXJT5lARid6I3gOJEEK2kuMTHX2S8=;
        b=Yz4ZINwtx5+eEQdKiF+6ujmSjvWb1TUcrUbXgwYx2qPxjACx8+iagrGQSe5zB5YVvT
         fwLPPy8HoDECk+boa9tHbECyx/Q/02eDMT+M3gwe7rjcEGW5woM+5yjT+cQVA0rDG7ko
         ssnfNUEQhBoAE/EA20FXpMO2tvbs4vEz7MwRwrHgaNRwO5LV/Tw854f6i5ZHUi/Y4wSa
         KV4+QeHPIOJL7uUKCCSf5iZDajeaej4Rog/92cwc1Mio3dufzgddrlG5uxWe+2px7iA5
         p3uK1vGPgYOV5Qf8pSI0SlWuWe00zP4J3cbNrsF+pswGFWl3MccOPeQAG026nrt9fn5j
         NsbQ==
X-Gm-Message-State: AHYfb5jVdPzDFBxo2rZzcSU6/bi9e2AKOGXIN50HeL0QpwhLlquZtTa4
	57obb+fk8m5Eirgl
X-Received: by 10.98.252.205 with SMTP id e196mr833496pfh.2.1503843066399;
        Sun, 27 Aug 2017 07:11:06 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.39.193 with SMTP id n184ls7750393ion.24.gmail; Sun, 27 Aug
 2017 07:11:04 -0700 (PDT)
X-Received: by 10.31.227.3 with SMTP id a3mr64135vkh.2.1503843064478;
        Sun, 27 Aug 2017 07:11:04 -0700 (PDT)
In-Reply-To: <1762295.OciJaA9sdk@tjmaciei-mobl1>
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: <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:34167
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/34167>

------=_Part_5391_811571578.1503843063950
Content-Type: multipart/alternative; 
	boundary="----=_Part_5392_626713149.1503843063950"

------=_Part_5392_626713149.1503843063950
Content-Type: text/plain; charset="UTF-8"

On Sunday, August 27, 2017 at 12:11:13 AM UTC-4, Thiago Macieira wrote:
>
> On Saturday, 26 August 2017 18:08:11 PDT Nicol Bolas wrote: 
> > I have a tuple. Why would I not just *use the tuple*? 
>
> Because tuples are horrible. From 
>         https://www.kdab.com/tuple-pair-cpp-apis/ 
>
> "Quick: When you design C++ APIs, when and how should you use pair and 
> tuple? 
> The answer is as simple as it is surprising: Never. Ever." 
>

> And yet some people will. So when interacting with those API, you need to 
> "correct" it with proper names. 
>

OK, the problem with tuples in APIs, as outlined in that post, is that they 
lack any semantic information. They have no meaningful variable names, and 
they have no meaningful type names.

If I'm using an API that uses tuples to the extent that it becomes 
difficult to understand the code when actually using a tuple, why would I 
be using an *unnamed* struct to solve this? Would it not make more sense to 
do this:

struct RealName
{
  RealName(const std::tuple<int, double> &);

  int a_member;
  double other_member;
};

And then in the actual function:

RealName s = std::make_tuple(1, 2.3);

This improves code reuse, since `RealName` can be used in multiple places. 
It improves readability, since `RealName` would convey semantic information 
about the collection of values that `decltype(s)` cannot. And so forth. The 
trivial repetition of typing the type names in two (or even three) places 
in `RealName` will be meaningless next to how often `RealName` is used.

Presumably, the reason I'm *not* using structured binding is because I want 
to pass the collection `s` around to other people, yes? Otherwise, you 
would just use structured binding to provide the semantic info. Given that 
this is the case, we need a proper name so that we understand what this 
aggregate actually means.

If this is a one-off case, where you're only calling one function that has 
a `tuple` API in one place... why are you creating an object for the values 
at all? If it's a one-off, use structured binding, or just tough-through 
the `get<>` interface for that one function.

What circumstances would I be in where I would be writing an *inline struct* 
to convert this object? If it happens frequently enough to obfuscate my 
code, the best solution is a named struct. If it's not that frequent, just 
use structured binding or the actual return value.

-- 
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/ff2ceb41-caca-4659-9a7d-4da9c2046810%40isocpp.org.

------=_Part_5392_626713149.1503843063950
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Sunday, August 27, 2017 at 12:11:13 AM UTC-4, Thiago Ma=
cieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Saturday, 26 A=
ugust 2017 18:08:11 PDT Nicol Bolas wrote:
<br>&gt; I have a tuple. Why would I not just *use the tuple*?
<br>
<br>Because tuples are horrible. From
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<a href=3D"https://www.=
kdab.com/tuple-pair-cpp-apis/" target=3D"_blank" rel=3D"nofollow" onmousedo=
wn=3D"this.href=3D&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.kd=
ab.com%2Ftuple-pair-cpp-apis%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGbr=
tXIHWqW8ZT3oSMGL-uJafTfuw&#39;;return true;" onclick=3D"this.href=3D&#39;ht=
tps://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.kdab.com%2Ftuple-pair-cpp-a=
pis%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGbrtXIHWqW8ZT3oSMGL-uJafTfuw=
&#39;;return true;">https://www.kdab.com/<wbr>tuple-pair-cpp-apis/</a>
<br>
<br>&quot;Quick: When you design C++ APIs, when and how should you use pair=
 and tuple?
<br>The answer is as simple as it is surprising: Never. Ever.&quot;
<br></blockquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>And yet some people will. So when interacting with those API, you need =
to=20
<br>&quot;correct&quot; it with proper names.
<br></blockquote><div><br>OK, the problem with tuples in APIs, as outlined =
in that post, is that they lack any semantic information. They have no mean=
ingful variable names, and they have no meaningful type names.<br><br>If I&=
#39;m using an API that uses tuples to the extent that it becomes difficult=
 to understand the code when actually using a tuple, why would I be using a=
n <i>unnamed</i> struct to solve this? Would it not make more sense to do t=
his:<br><br><div style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-wra=
p: break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div clas=
s=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #606;" class=3D"styled-by-prettify">RealName<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span st=
yle=3D"color: #606;" class=3D"styled-by-prettify">RealName</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">tuple</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">int</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">double</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&amp;);</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> a_member</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">double</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> other_member</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">};</span></div></code></div><br>And then in the actual function=
:<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: #606;" class=3D"styled-by-prettif=
y">RealName</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> s </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">make_tuple</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-b=
y-prettify">2.3</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">);</span></div></code></div><br>This improves code reuse, since `RealN=
ame` can be used in multiple places. It improves readability, since `RealNa=
me` would convey semantic information about the collection of values that `=
decltype(s)` cannot. And so forth. The trivial repetition of typing the typ=
e names in two (or even three) places in `RealName` will be meaningless nex=
t to how often `RealName` is used.<br><br>Presumably, the reason I&#39;m <i=
>not</i> using structured binding is because I want to pass the collection =
`s` around to other people, yes? Otherwise, you would just use structured b=
inding to provide the semantic info. Given that this is the case, we need a=
 proper name so that we understand what this aggregate actually means.<br><=
br>If this is a one-off case, where you&#39;re only calling one function th=
at has a `tuple` API in one place... why are you creating an object for the=
 values at all? If it&#39;s a one-off, use structured binding, or just toug=
h-through the `get&lt;&gt;` interface for that one function.<br><br>What ci=
rcumstances would I be in where I would be writing an <i>inline struct</i> =
to convert this object? If it happens frequently enough to obfuscate my cod=
e, the best solution is a named struct. If it&#39;s not that frequent, just=
 use structured binding or the actual return value.</div></div>

<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/ff2ceb41-caca-4659-9a7d-4da9c2046810%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ff2ceb41-caca-4659-9a7d-4da9c2046810=
%40isocpp.org</a>.<br />

------=_Part_5392_626713149.1503843063950--

------=_Part_5391_811571578.1503843063950--

.
