Topic: Anonymous or unnamed variables


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Tue, 13 Nov 2012 22:46:58 +0100
Raw View
Hi,

Quite often we need to name a guard variable which is not used other
than in the declaration to do some action on the destruction (raii), e.g.

{
   std::lock_guard<std::mutex> guard(mtx);
   // ...
}

Giving a name to these guard variables doesn't adds value to the
expression, and some of us use to name them '_'

{
   std::lock_guard<std::mutex> _(mtx);
   // ...
}

Of course we can not include two of them on the same scope without using
a more specific name as the name conflict.

{
   std::lock_guard<std::mutex> g1(mtx1);
   std::lock_guard<std::mutex> g2(mtx2);
   // ...
}

Do you think it could be worth adding some kind of anonymous variable
that avoid having to name these kind of variables? E.g.we could use the
token '...'

{
   std::lock_guard<std::mutex> ...(mtx1);
   std::lock_guard<std::mutex> ...(mtx2);
   // ...
}

One of the features of these unnamed variables could be that we can not
do anything with, so maybe the compiler could take advantage in order to
optimize the code.

I recognize that the added value is minor, but I'm sure that you have
already desired to not name these variables.

Best,
Vicente

--




.


Author: Nevin Liber <nevin@eviloverlord.com>
Date: Tue, 13 Nov 2012 16:25:41 -0600
Raw View
--0015174a05503deb1004ce67fd15
Content-Type: text/plain; charset=ISO-8859-1

On 13 November 2012 15:46, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:

>
> One of the features of these unnamed variables could be that we can not do
> anything with, so maybe the compiler could take advantage in order to
> optimize the code.
>

I can't imagine how.  Do you have a scenario in mind?


> I recognize that the added value is minor, but I'm sure that you have
> already desired to not name these variables.
>

Given the cost to adding language features, I just don't see a compelling
case.
--
 Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  (847) 691-1404

--




--0015174a05503deb1004ce67fd15
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On 13 November 2012 15:46, Vicente J. Botet Escriba <span dir=3D"ltr">&lt;<=
a href=3D"mailto:vicente.botet@wanadoo.fr" target=3D"_blank">vicente.botet@=
wanadoo.fr</a>&gt;</span> wrote:<br><div class=3D"gmail_quote"><blockquote =
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex">

<br>
One of the features of these unnamed variables could be that we can not do =
anything with, so maybe the compiler could take advantage in order to optim=
ize the code.<br></blockquote><div><br>I can&#39;t imagine how.=A0 Do you h=
ave a scenario in mind?<br>

=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;borde=
r-left:1px #ccc solid;padding-left:1ex">
I recognize that the added value is minor, but I&#39;m sure that you have a=
lready desired to not name these variables.<br></blockquote><div><br>Given =
the cost to adding language features, I just don&#39;t see a compelling cas=
e.<br>

</div></div>-- <br>=A0Nevin &quot;:-)&quot; Liber=A0 &lt;mailto:<a href=3D"=
mailto:nevin@eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>=
&gt;=A0 (847) 691-1404<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

--0015174a05503deb1004ce67fd15--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 14 Nov 2012 07:11:53 +0100
Raw View
This is a multi-part message in MIME format.
--------------080305000109020300090307
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 13/11/12 23:25, Nevin Liber a =E9crit :
> On 13 November 2012 15:46, Vicente J. Botet Escriba=20
> <vicente.botet@wanadoo.fr <mailto:vicente.botet@wanadoo.fr>> wrote:
>
>
>     One of the features of these unnamed variables could be that we
>     can not do anything with, so maybe the compiler could take
>     advantage in order to optimize the code.
>
>
> I can't imagine how.  Do you have a scenario in mind?
No, As I said I'm not a compiler writer :(
>
>     I recognize that the added value is minor, but I'm sure that you
>     have already desired to not name these variables.
>
>
> Given the cost to adding language features, I just don't see a=20
> compelling case.
>
I just wanted to share a minor need that 'don't name what you don't=20
need' ;-).
I understand that we can concentrate in more important features.

Vicente

--=20




--------------080305000109020300090307
Content-Type: text/html; charset=ISO-8859-1

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Le 13/11/12 23:25, Nevin Liber a
      &eacute;crit&nbsp;:<br>
    </div>
    <blockquote
cite="mid:CAGg_6+Ncm_JFWJBpcQorr9gJi8FGdAvrumzGo3NBXaztadnBsA@mail.gmail.com"
      type="cite">On 13 November 2012 15:46, Vicente J. Botet Escriba <span
        dir="ltr">&lt;<a moz-do-not-send="true"
          href="mailto:vicente.botet@wanadoo.fr" target="_blank">vicente.botet@wanadoo.fr</a>&gt;</span>
      wrote:<br>
      <div class="gmail_quote">
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br>
          One of the features of these unnamed variables could be that
          we can not do anything with, so maybe the compiler could take
          advantage in order to optimize the code.<br>
        </blockquote>
        <div><br>
          I can't imagine how.&nbsp; Do you have a scenario in mind?<br>
        </div>
      </div>
    </blockquote>
    No, As I said I'm not a compiler writer :(<br>
    <blockquote
cite="mid:CAGg_6+Ncm_JFWJBpcQorr9gJi8FGdAvrumzGo3NBXaztadnBsA@mail.gmail.com"
      type="cite">
      <div class="gmail_quote">
        <div> &nbsp;</div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex"> I recognize
          that the added value is minor, but I'm sure that you have
          already desired to not name these variables.<br>
        </blockquote>
        <div><br>
          Given the cost to adding language features, I just don't see a
          compelling case.<br>
        </div>
      </div>
      <br>
    </blockquote>
    I just wanted to share a minor need that 'don't name what you don't
    need' ;-). <br>
    I understand that we can concentrate in more important features.<br>
    <br>
    Vicente<br>
    <br>
  </body>
</html>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

--------------080305000109020300090307--

.