Topic: Any plans to fix enum to string problems?


Author: nx02columbia@gmail.com
Date: Sat, 10 Nov 2012 20:25:41 -0800 (PST)
Raw View
------=_Part_105_33371135.1352607941986
Content-Type: text/plain; charset=ISO-8859-1

Hi,
I guess everybody knows about/ has written boilerplate code that translates
enums to strings... that beside being totally redundant
often(IMHX(eXperience ) ) violates  DRY principle.
Any plans to make to_string() accept enums ?

--




------=_Part_105_33371135.1352607941986
Content-Type: text/html; charset=ISO-8859-1

Hi, <br>I guess everybody knows about/ has written boilerplate code that translates enums to strings... that beside being totally redundant often(IMHX(eXperience ) ) violates&nbsp; DRY principle.<br>Any plans to make to_string() accept enums ?<br>

<p></p>

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

------=_Part_105_33371135.1352607941986--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 10 Nov 2012 21:51:41 -0800 (PST)
Raw View
------=_Part_21_21399871.1352613101113
Content-Type: text/plain; charset=ISO-8859-1

On Saturday, November 10, 2012 8:25:42 PM UTC-8, nx02co...@gmail.com wrote:
>
> Hi,
> I guess everybody knows about/ has written boilerplate code that
> translates enums to strings... that beside being totally redundant
> often(IMHX(eXperience ) ) violates  DRY principle.
> Any plans to make to_string() accept enums ?
>

The "plan" is to implement reflection, which will allow this in addition to
other things. `to_string` is a library function; it can't magic an
enumerator's string name into being, since all it sees is an integer. So
we'll get it, just not with `to_string`.

--




------=_Part_21_21399871.1352613101113
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Saturday, November 10, 2012 8:25:42 PM UTC-8, nx02co...@gmail.com wrote:=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;">Hi, <br>I guess everybody know=
s about/ has written boilerplate code that translates enums to strings... t=
hat beside being totally redundant often(IMHX(eXperience ) ) violates&nbsp;=
 DRY principle.<br>Any plans to make to_string() accept enums ?<br></blockq=
uote><div><br>The "plan" is to implement reflection, which will allow this =
in addition to other things. `to_string` is a library function; it can't ma=
gic an enumerator's string name into being, since all it sees is an integer=
.. So we'll get it, just not with `to_string`.<br></div>

<p></p>

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

------=_Part_21_21399871.1352613101113--

.


Author: Rob Meijer <pibara@gmail.com>
Date: Sun, 11 Nov 2012 09:27:38 +0100
Raw View
--e89a8f839bb725af6b04ce33f586
Content-Type: text/plain; charset=ISO-8859-1

On Nov 11, 2012 6:51 AM, "Nicol Bolas" <jmckesson@gmail.com> wrote:
>
> On Saturday, November 10, 2012 8:25:42 PM UTC-8, nx02co...@gmail.comwrote:
>>
>> Hi,
>> I guess everybody knows about/ has written boilerplate code that
translates enums to strings... that beside being totally redundant
often(IMHX(eXperience ) ) violates  DRY principle.
>> Any plans to make to_string() accept enums ?
>
>
> The "plan" is to implement reflection, which will allow this in addition
to other things. `to_string` is a library function; it can't magic an
enumerator's string name into being, since all it sees is an integer. So
we'll get it, just not with `to_string`.
>
> --

Shouldnt reflection be a last resort? It feels like killing a musquito with
a bazooka.

--




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

<p><br>
On Nov 11, 2012 6:51 AM, &quot;Nicol Bolas&quot; &lt;<a href=3D"mailto:jmck=
esson@gmail.com">jmckesson@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; On Saturday, November 10, 2012 8:25:42 PM UTC-8, <a href=3D"mailto:nx0=
2co...@gmail.com">nx02co...@gmail.com</a> wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi, <br>
&gt;&gt; I guess everybody knows about/ has written boilerplate code that t=
ranslates enums to strings... that beside being totally redundant often(IMH=
X(eXperience ) ) violates=A0 DRY principle.<br>
&gt;&gt; Any plans to make to_string() accept enums ?<br>
&gt;<br>
&gt;<br>
&gt; The &quot;plan&quot; is to implement reflection, which will allow this=
 in addition to other things. `to_string` is a library function; it can&#39=
;t magic an enumerator&#39;s string name into being, since all it sees is a=
n integer. So we&#39;ll get it, just not with `to_string`.<br>

&gt;<br>
&gt; -- </p>
<p>Shouldnt reflection be a last resort? It feels like killing a musquito w=
ith a bazooka. </p>

<p></p>

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

--e89a8f839bb725af6b04ce33f586--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 11 Nov 2012 00:57:15 -0800 (PST)
Raw View
------=_Part_1884_21043754.1352624235919
Content-Type: text/plain; charset=ISO-8859-1



On Sunday, November 11, 2012 12:27:39 AM UTC-8, pibara wrote:
>
>
> On Nov 11, 2012 6:51 AM, "Nicol Bolas" <jmck...@gmail.com <javascript:>>
> wrote:
> >
> > On Saturday, November 10, 2012 8:25:42 PM UTC-8, nx02co...@gmail.comwrote:
> >>
> >> Hi,
> >> I guess everybody knows about/ has written boilerplate code that
> translates enums to strings... that beside being totally redundant
> often(IMHX(eXperience ) ) violates  DRY principle.
> >> Any plans to make to_string() accept enums ?
> >
> >
> > The "plan" is to implement reflection, which will allow this in addition
> to other things. `to_string` is a library function; it can't magic an
> enumerator's string name into being, since all it sees is an integer. So
> we'll get it, just not with `to_string`.
> >
> > --
>
> Shouldnt reflection be a last resort? It feels like killing a musquito
> with a bazooka.
>
That *is* reflection. Converting a number into an enumerator string name is
reflection. As is converting an enumerator string name into a number. It
would require the same machinery (ie: the compiler creating a runtime-list
of appropriate enumerator string names and numbers). And so forth. It's
reflection; just a very narrow use case of it.

Also, don't forget: enumerators don't have to be unique. The same
enumerator value can be used by many enumerators in an enumeration. So the
operation of taking an integer and converting it into a string name is
already lossy.

--




------=_Part_1884_21043754.1352624235919
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><br>On Sunday, November 11, 2012 12:27:39 AM UTC-8, pibara wrote:<block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;"><p><br>
On Nov 11, 2012 6:51 AM, "Nicol Bolas" &lt;<a href=3D"javascript:" target=
=3D"_blank" gdf-obfuscated-mailto=3D"J8af3n-yrnAJ">jmck...@gmail.com</a>&gt=
; wrote:<br>
&gt;<br>
&gt; On Saturday, November 10, 2012 8:25:42 PM UTC-8, <a>nx02co...@gmail.co=
m</a> wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi, <br>
&gt;&gt; I guess everybody knows about/ has written boilerplate code that t=
ranslates enums to strings... that beside being totally redundant often(IMH=
X(eXperience ) ) violates&nbsp; DRY principle.<br>
&gt;&gt; Any plans to make to_string() accept enums ?<br>
&gt;<br>
&gt;<br>
&gt; The "plan" is to implement reflection, which will allow this in additi=
on to other things. `to_string` is a library function; it can't magic an en=
umerator's string name into being, since all it sees is an integer. So we'l=
l get it, just not with `to_string`.<br>

&gt;<br>
&gt; -- </p>
<p>Shouldnt reflection be a last resort? It feels like killing a musquito w=
ith a bazooka. </p></blockquote><div>That <i>is</i> reflection. Converting =
a number into an enumerator string name is reflection. As is converting an =
enumerator string name into a number. It would require the same machinery (=
ie: the compiler creating a=20
runtime-list of appropriate enumerator string names and numbers). And so
 forth. It's reflection; just a very narrow use case of it.<br><br>Also, do=
n't forget: enumerators don't have to be unique. The same enumerator value =
can be used by many enumerators in an enumeration. So the operation of taki=
ng an integer and converting it into a string name is already lossy.<br></d=
iv>

<p></p>

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

------=_Part_1884_21043754.1352624235919--

.


Author: Rob Meijer <pibara@gmail.com>
Date: Sun, 11 Nov 2012 10:57:00 +0100
Raw View
--14dae9340f6fba01e104ce3534fc
Content-Type: text/plain; charset=ISO-8859-1

2012/11/11 Nicol Bolas <jmckesson@gmail.com>

>
>
> On Sunday, November 11, 2012 12:27:39 AM UTC-8, pibara wrote:
>
>>
>> On Nov 11, 2012 6:51 AM, "Nicol Bolas" <jmck...@gmail.com> wrote:
>> >
>> > On Saturday, November 10, 2012 8:25:42 PM UTC-8, nx02co...@gmail.comwrote:
>> >>
>> >> Hi,
>> >> I guess everybody knows about/ has written boilerplate code that
>> translates enums to strings... that beside being totally redundant
>> often(IMHX(eXperience ) ) violates  DRY principle.
>> >> Any plans to make to_string() accept enums ?
>> >
>> >
>> > The "plan" is to implement reflection, which will allow this in
>> addition to other things. `to_string` is a library function; it can't magic
>> an enumerator's string name into being, since all it sees is an integer. So
>> we'll get it, just not with `to_string`.
>> >
>> > --
>>
>> Shouldnt reflection be a last resort? It feels like killing a musquito
>> with a bazooka.
>>
> That *is* reflection. Converting a number into an enumerator string name
> is reflection. As is converting an enumerator string name into a number. It
> would require the same machinery (ie: the compiler creating a runtime-list
> of appropriate enumerator string names and numbers). And so forth. It's
> reflection; just a very narrow use case of it.
>
> Also, don't forget: enumerators don't have to be unique. The same
> enumerator value can be used by many enumerators in an enumeration. So the
> operation of taking an integer and converting it into a string name is
> already lossy.
>
>
>
Maybe I misunderstood, but I thought reflection referred to an extended
RTTI system that allows all kind of run-time trickery. If we start using
the existence of RTTI constructs as an excuse to not provide desired
language features as compile time features than C++ runs the risk of
regressing into a semi VM-language.

--




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

<div><br></div><div class=3D"gmail_extra"><div class=3D"gmail_quote">2012/1=
1/11 Nicol Bolas <span dir=3D"ltr">&lt;<a href=3D"mailto:jmckesson@gmail.co=
m" target=3D"_blank">jmckesson@gmail.com</a>&gt;</span><br><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;b=
order-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"=
>
<br><br>On Sunday, November 11, 2012 12:27:39 AM UTC-8, pibara wrote:<div><=
div class=3D"h5"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px =
0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-l=
eft-style:solid;padding-left:1ex">
<p><br>
On Nov 11, 2012 6:51 AM, &quot;Nicol Bolas&quot; &lt;<a>jmck...@gmail.com</=
a>&gt; wrote:<br>
&gt;<br>
&gt; On Saturday, November 10, 2012 8:25:42 PM UTC-8, <a>nx02co...@gmail.co=
m</a> wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi, <br>
&gt;&gt; I guess everybody knows about/ has written boilerplate code that t=
ranslates enums to strings... that beside being totally redundant often(IMH=
X(eXperience ) ) violates=A0 DRY principle.<br>
&gt;&gt; Any plans to make to_string() accept enums ?<br>
&gt;<br>
&gt;<br>
&gt; The &quot;plan&quot; is to implement reflection, which will allow this=
 in addition to other things. `to_string` is a library function; it can&#39=
;t magic an enumerator&#39;s string name into being, since all it sees is a=
n integer. So we&#39;ll get it, just not with `to_string`.<br>


&gt;<br>
&gt; -- </p>
<p>Shouldnt reflection be a last resort? It feels like killing a musquito w=
ith a bazooka. </p></blockquote></div></div><div>That <i>is</i> reflection.=
 Converting a number into an enumerator string name is reflection. As is co=
nverting an enumerator string name into a number. It would require the same=
 machinery (ie: the compiler creating a=20
runtime-list of appropriate enumerator string names and numbers). And so
 forth. It&#39;s reflection; just a very narrow use case of it.<br><br>Also=
, don&#39;t forget: enumerators don&#39;t have to be unique. The same enume=
rator value can be used by many enumerators in an enumeration. So the opera=
tion of taking an integer and converting it into a string name is already l=
ossy.<span class=3D""><font color=3D"#888888"><br>
</font></span></div><span class=3D""><font color=3D"#888888">

<p></p><br></font></span></blockquote><div><div><br></div><div>Maybe I misu=
nderstood, but=A0I thought reflection referred to an extended RTTI system t=
hat allows all kind of run-time trickery. If we start using the existence o=
f RTTI constructs as an excuse to not provide desired language features as =
compile time features than C++ runs the risk of regressing=A0into a semi VM=
-language.</div>
</div></div><br></div>

<p></p>

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

--14dae9340f6fba01e104ce3534fc--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 11 Nov 2012 12:14:23 +0200
Raw View
On 11 November 2012 11:57, Rob Meijer <pibara@gmail.com> wrote:
> Maybe I misunderstood, but I thought reflection referred to an extended RTTI
> system that allows all kind of run-time trickery. If we start using the
> existence of RTTI constructs as an excuse to not provide desired language
> features as compile time features than C++ runs the risk of regressing into
> a semi VM-language.

No, the reflection that was mentioned previously would happen at compile-time.

--




.


Author: nx02columbia@gmail.com
Date: Sun, 11 Nov 2012 11:57:46 -0800 (PST)
Raw View
------=_Part_179_2536706.1352663866673
Content-Type: text/plain; charset=ISO-8859-1

good to hear it..
BTW I understand that to_string is lib function, but I think there are
examples of functions baked into language like Herb says it. I think he
said for_each is function like that... I might be wrong, but basically it
would be language hack to make obvious things easily doable for user while
making language spec messy. Either way ANY solution is great, as long as it
is DRY. Also I hope for enum that has 15 values we wont have to write aprox
15 lines to get to_string behaviour. :)

On Sunday, November 11, 2012 7:51:41 AM UTC+2, Nicol Bolas wrote:
>
> On Saturday, November 10, 2012 8:25:42 PM UTC-8, nx02co...@gmail.comwrote:
>>
>> Hi,
>> I guess everybody knows about/ has written boilerplate code that
>> translates enums to strings... that beside being totally redundant
>> often(IMHX(eXperience ) ) violates  DRY principle.
>> Any plans to make to_string() accept enums ?
>>
>
> The "plan" is to implement reflection, which will allow this in addition
> to other things. `to_string` is a library function; it can't magic an
> enumerator's string name into being, since all it sees is an integer. So
> we'll get it, just not with `to_string`.
>

--




------=_Part_179_2536706.1352663866673
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

good to hear it..<br>BTW I understand that to_string is lib function, but I=
 think there are examples of functions baked into language like Herb says i=
t. I think he said for_each is function like that... I might be wrong, but =
basically it would be language hack to make obvious things easily doable fo=
r user while making language spec messy. Either way ANY solution is great, =
as long as it is DRY. Also I hope for enum that has 15 values we wont have =
to write aprox 15 lines to get to_string behaviour. :)<br><br>On Sunday, No=
vember 11, 2012 7:51:41 AM UTC+2, Nicol Bolas wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc soli=
d;padding-left: 1ex;">On Saturday, November 10, 2012 8:25:42 PM UTC-8, <a>n=
x02co...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, <b=
r>I guess everybody knows about/ has written boilerplate code that translat=
es enums to strings... that beside being totally redundant often(IMHX(eXper=
ience ) ) violates&nbsp; DRY principle.<br>Any plans to make to_string() ac=
cept enums ?<br></blockquote><div><br>The "plan" is to implement reflection=
, which will allow this in addition to other things. `to_string` is a libra=
ry function; it can't magic an enumerator's string name into being, since a=
ll it sees is an integer. So we'll get it, just not with `to_string`.<br></=
div></blockquote>

<p></p>

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

------=_Part_179_2536706.1352663866673--

.