www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - version()

reply Manu <turkeyman gmail.com> writes:
--20cf30363f356fb5d504b699afe3
Content-Type: text/plain; charset=UTF-8

Why can't I do this:

version( linux || OSX )
{
  something common to each
}

???


This is not acceptable:

version( MinGW )
{
version = linuxOrMinGW;
}
else version( linux )
{
version = linuxOrMinGW;
}

version( linuxOrMinGW )
{
  seriously...?
}


Surely basic logical expressions within a version seem not only logical,
but also very necessary?
There must be a reason this is impossible, or else I can't believe it's not
already like that...

--20cf30363f356fb5d504b699afe3
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Why can&#39;t I do this:<div><br></div><div><font face=3D"&#39;courier new&=
#39;, monospace">version( linux || OSX )</font></div><div><font face=3D"&#3=
9;courier new&#39;, monospace">{</font></div><div><font face=3D"&#39;courie=
r new&#39;, monospace">=C2=A0 something common to each</font></div>
<div><font face=3D"&#39;courier new&#39;, monospace">}</font></div><div><br=
</div><div>???</div><div><br></div><div><br></div><div>This is not accepta=

ospace">version( MinGW )</font></div> <div><font face=3D"&#39;courier new&#39;, monospace">{</font></div><div><fo= nt face=3D"&#39;courier new&#39;, monospace"><span class=3D"Apple-tab-span"= style=3D"white-space:pre"> </span>version =3D linuxOrMinGW;</font></div><d= iv><font face=3D"&#39;courier new&#39;, monospace">}</font></div> <div><font face=3D"&#39;courier new&#39;, monospace">else version( linux )<= /font></div><div><font face=3D"&#39;courier new&#39;, monospace">{</font></= div><div><font face=3D"&#39;courier new&#39;, monospace"><span class=3D"App= le-tab-span" style=3D"white-space:pre"> </span>version =3D linuxOrMinGW;</f= ont></div> <div><font face=3D"&#39;courier new&#39;, monospace">}</font></div><div><fo= nt face=3D"&#39;courier new&#39;, monospace"><br></font></div><div><font fa= ce=3D"&#39;courier new&#39;, monospace">version( linuxOrMinGW )</font></div=
<div>

ont face=3D"&#39;courier new&#39;, monospace">=C2=A0 seriously...?</font></= div><div><font face=3D"&#39;courier new&#39;, monospace">}</font></div><div=
<br></div>

not only logical, but also very necessary?</div><div>There must be a reason= this is impossible, or else I can&#39;t believe it&#39;s not already like = that...</div> --20cf30363f356fb5d504b699afe3--
Jan 15 2012
next sibling parent Mike Parker <aldacron gmail.com> writes:
On 1/16/2012 8:44 AM, Manu wrote:
 Why can't I do this:

 version( linux || OSX )
 {
    something common to each
 }

 ???


 This is not acceptable:

 version( MinGW )
 {
 version = linuxOrMinGW;
 }
 else version( linux )
 {
 version = linuxOrMinGW;
 }

 version( linuxOrMinGW )
 {
    seriously...?
 }


 Surely basic logical expressions within a version seem not only logical,
 but also very necessary?
 There must be a reason this is impossible, or else I can't believe it's
 not already like that...

This is something I've wanted ever since I first started using D. Really annoying when you need to do the same sort of version checks across multiple modules. One workaround: ---------------- module myconfig; version(MingW) { enum bool linuxOrMingW = true; } else version(linux) { enum bool linuxOrMingW = true; } else { enum bool linuxOrMingW = false; } ----------------- module foo; import myconfig; static if(linuxOrMingW) { ... } -----------------
Jan 15 2012
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-01-16 00:44, Manu wrote:
 Why can't I do this:

 version( linux || OSX )
 {
    something common to each
 }

 ???


 This is not acceptable:

 version( MinGW )
 {
 version = linuxOrMinGW;
 }
 else version( linux )
 {
 version = linuxOrMinGW;
 }

 version( linuxOrMinGW )
 {
    seriously...?
 }


 Surely basic logical expressions within a version seem not only logical,
 but also very necessary?
 There must be a reason this is impossible, or else I can't believe it's
 not already like that...

A workaround is to declare variables and use static ifs: https://github.com/jacob-carlborg/orbit/blob/master/orbit/util/Version.d -- /Jacob Carlborg
Jan 15 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-01-16 08:33, Manu wrote:
 On 16 January 2012 09:28, Jacob Carlborg <doob me.com
 <mailto:doob me.com>> wrote:

     On 2012-01-16 00:44, Manu wrote:

         Why can't I do this:

         version( linux || OSX )
         {
            something common to each
         }

         ???


         This is not acceptable:

         version( MinGW )
         {
         version = linuxOrMinGW;
         }
         else version( linux )
         {
         version = linuxOrMinGW;
         }

         version( linuxOrMinGW )
         {
            seriously...?
         }


         Surely basic logical expressions within a version seem not only
         logical,
         but also very necessary?
         There must be a reason this is impossible, or else I can't
         believe it's
         not already like that...


     A workaround is to declare variables and use static ifs:

     https://github.com/jacob-__carlborg/orbit/blob/master/__orbit/util/Version.d
     <https://github.com/jacob-carlborg/orbit/blob/master/orbit/util/Version.d>


 ... these aren't acceptable work arounds, in this case, you're written a
 whole module to subvert the insanity! :)
 At bare minimum, the version list/map/table/whatever it is should be
 exposed to static-if, without having to create a module like the one you
 just described.

It is a workaround that works, regardless if you think it's acceptable or not, and I've already done most of the work so you don't have to. -- /Jacob Carlborg
Jan 15 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--002354470e0cb273f004b6a03bc4
Content-Type: text/plain; charset=UTF-8

On 16 January 2012 09:28, Jacob Carlborg <doob me.com> wrote:

 On 2012-01-16 00:44, Manu wrote:

 Why can't I do this:

 version( linux || OSX )
 {
   something common to each
 }

 ???


 This is not acceptable:

 version( MinGW )
 {
 version = linuxOrMinGW;
 }
 else version( linux )
 {
 version = linuxOrMinGW;
 }

 version( linuxOrMinGW )
 {
   seriously...?
 }


 Surely basic logical expressions within a version seem not only logical,
 but also very necessary?
 There must be a reason this is impossible, or else I can't believe it's
 not already like that...

A workaround is to declare variables and use static ifs: https://github.com/jacob-**carlborg/orbit/blob/master/** orbit/util/Version.d<https://github.com/jacob-carlborg/orbit/blob/master/orbit/util/Version.d>

... these aren't acceptable work arounds, in this case, you're written a whole module to subvert the insanity! :) At bare minimum, the version list/map/table/whatever it is should be exposed to static-if, without having to create a module like the one you just described. --002354470e0cb273f004b6a03bc4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 16 January 2012 09:28, Jacob Carlborg <span d= ir=3D"ltr">&lt;<a href=3D"mailto:doob me.com">doob me.com</a>&gt;</span> wr= ote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border= -left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 2012-01-16 00:44, Manu wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Why can&#39;t I do this:<br> <br> version( linux || OSX )<br> {<br> =C2=A0 something common to each<br> }<br> <br> ???<br> <br> <br> This is not acceptable:<br> <br> version( MinGW )<br> {<br> version =3D linuxOrMinGW;<br> }<br> else version( linux )<br> {<br> version =3D linuxOrMinGW;<br> }<br> <br> version( linuxOrMinGW )<br> {<br> =C2=A0 seriously...?<br> }<br> <br> <br> Surely basic logical expressions within a version seem not only logical,<br=

There must be a reason this is impossible, or else I can&#39;t believe it&#= 39;s<br> not already like that...<br> </blockquote> <br></div> A workaround is to declare variables and use static ifs:<br> <br> <a href=3D"https://github.com/jacob-carlborg/orbit/blob/master/orbit/util/V= ersion.d" target=3D"_blank">https://github.com/jacob-<u></u>carlborg/orbit/= blob/master/<u></u>orbit/util/Version.d</a></blockquote><div><br></div><div=

ten a whole module to subvert the insanity! :)</div><div>At bare minimum, t= he version list/map/table/whatever it is should be exposed to static-if, wi= thout having to create a module like the one you just described.</div> </div> --002354470e0cb273f004b6a03bc4--
Jan 15 2012
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
I somewhat rarely use version anymore. I used
to use it for different client customizations
to my app, but you can't turn features on and
off in a a central file like that, since the
version= doesn't affect other modules.

I switched for a while to static if like this:

version(client_a)
  enum feature_x = true;
version(client_b)
  enum feature_x = false;


== other file ==

static if(feature_x)
   void feature_x_impl() {}



But, now, I have a way of doing it without
version, and it's even better.


client_a_config.d:
===
module app.config;
enum feature_x = true;
===

client_b_config.d:
===
module app.config;
enum feature_x = false;
===


Real file:
===
import app.config;

static if(feature_x)
  // implement
===



Then, I pick the desired version just by picking
the file on the command line.


dmd app.d client_a_config.d # build client A's version
dmd app.d client_b_config.d # build client B's version



So, there's no version stuff in there at all... I now
think version is *almost* useless. Could probably use
this for operating system versions too, putting the
common components in a shared file.
Jan 16 2012
prev sibling parent Manu <turkeyman gmail.com> writes:
--20cf3005dee22f0cc204b6ac194f
Content-Type: text/plain; charset=UTF-8

On 16 January 2012 23:19, Adam D. Ruppe <destructionator gmail.com> wrote:

 I somewhat rarely use version anymore. I used
 to use it for different client customizations
 to my app, but you can't turn features on and
 off in a a central file like that, since the
 version= doesn't affect other modules.

 I switched for a while to static if like this:

 version(client_a)
  enum feature_x = true;
 version(client_b)
  enum feature_x = false;


 == other file ==

 static if(feature_x)
  void feature_x_impl() {}



 But, now, I have a way of doing it without
 version, and it's even better.


 client_a_config.d:
 ===
 module app.config;
 enum feature_x = true;
 ===

 client_b_config.d:
 ===
 module app.config;
 enum feature_x = false;
 ===


 Real file:
 ===
 import app.config;

 static if(feature_x)
  // implement
 ===



 Then, I pick the desired version just by picking
 the file on the command line.


 dmd app.d client_a_config.d # build client A's version
 dmd app.d client_b_config.d # build client B's version



 So, there's no version stuff in there at all... I now
 think version is *almost* useless. Could probably use
 this for operating system versions too, putting the
 common components in a shared file.

The fact that everyone has their own work-around, and everyone has a DIFFERENT work around is hard evidence that version() is insufficient, and the current design is making D code WORSE. Even Walter describes and supports the work-arounds to use in his poses from years ago. I can see absolutely no evidence that performing logical expressions on versions is not required by any cross platform applications, including phobos! However now, instead of expressing the logic in a concise and familiar fashion, you have to try and decode each individuals own personal work-around scheme, at the expense of 10s of lines of really ugly spaghetti, and for absolutely no benefit. There is hard evidence people can't work without version logic, so why continue to deny it? Using '} else {' as a substitute for ! for example, you're STILL typing '!', you're just writing it in the ugliest and least intuitive way possible. Are people REALLY more likely to mis-read/misunderstand the '!' in the expression than miss the obscure 'else' statement to fake the same effect? Using 'version(A) version(B)' as a substitute for &&... it's still &&, except it's way longer, and it's certainly not as clear that you're really performing a boolean &&. Why not just write what it is? And ||, the MOST common operation to want to perform... let's not mention the work around, it's clearly the worst. Suffice to say, you're still producing OR logic, but again, writing it in a really archaic fashion. People ARE writing these logical constructs whether they use a clear logical expressions or not... why not just let them write it between the parentheses in a clear and concise manner, than scatter and obscure the logic across 10 lines? --20cf3005dee22f0cc204b6ac194f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 16 January 2012 23:19, Adam D. Ruppe <span di= r=3D"ltr">&lt;<a href=3D"mailto:destructionator gmail.com">destructionator = gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style= =3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> I somewhat rarely use version anymore. I used<br> to use it for different client customizations<br> to my app, but you can&#39;t turn features on and<br> off in a a central file like that, since the<br> version=3D doesn&#39;t affect other modules.<br> <br> I switched for a while to static if like this:<br> <br> version(client_a)<br> =C2=A0enum feature_x =3D true;<br> version(client_b)<br> =C2=A0enum feature_x =3D false;<br> <br> <br> =3D=3D other file =3D=3D<br> <br> static if(feature_x)<br> =C2=A0void feature_x_impl() {}<br> <br> <br> <br> But, now, I have a way of doing it without<br> version, and it&#39;s even better.<br> <br> <br> client_a_config.d:<br> =3D=3D=3D<br> module app.config;<br> enum feature_x =3D true;<br> =3D=3D=3D<br> <br> client_b_config.d:<br> =3D=3D=3D<br> module app.config;<br> enum feature_x =3D false;<br> =3D=3D=3D<br> <br> <br> Real file:<br> =3D=3D=3D<br> import app.config;<br> <br> static if(feature_x)<br> =C2=A0// implement<br> =3D=3D=3D<br> <br> <br> <br> Then, I pick the desired version just by picking<br> the file on the command line.<br> <br> <br> dmd app.d client_a_config.d # build client A&#39;s version<br> dmd app.d client_b_config.d # build client B&#39;s version<br> <br> <br> <br> So, there&#39;s no version stuff in there at all... I now<br> think version is *almost* useless. Could probably use<br> this for operating system versions too, putting the<br> common components in a shared file.<br> </blockquote></div><div><br></div><div>The fact that everyone has their own= work-around, and everyone has a DIFFERENT work around is hard evidence tha= t version() is insufficient, and the current design is making D code WORSE.= </div> <div>Even Walter describes and supports the work-arounds to use in his pose= s from years ago.<br><br></div><div>I can see absolutely no evidence that p= erforming logical expressions on versions is not required by any cross plat= form applications, including phobos! However now, instead of expressing the= logic in a concise and familiar fashion, you have to try and decode each i= ndividuals own personal work-around scheme, at the expense of 10s of lines = of really ugly spaghetti, and for absolutely no benefit.</div> <div><br></div><div>There is hard evidence people can&#39;t work without ve= rsion logic, so why continue to deny it?</div><div><br></div><div>Using &#3= 9;} else {&#39; as a substitute for ! for example, you&#39;re STILL typing = &#39;!&#39;, you&#39;re just writing it in the ugliest and least intuitive = way possible. Are people REALLY more likely to mis-read/misunderstand the &= #39;!&#39; in the expression than miss the obscure &#39;else&#39; statement= to fake the same effect?</div> <div>Using &#39;version(A) version(B)&#39; as a substitute for &amp;&amp;..= . it&#39;s still &amp;&amp;, except it&#39;s way longer, and it&#39;s certa= inly not as clear that you&#39;re really performing a boolean &amp;&amp;. W= hy not just write what it is?</div> <div>And ||, the MOST common operation to want to perform... let&#39;s not = mention the work around, it&#39;s clearly the worst. Suffice to say, you&#3= 9;re still producing OR logic, but again, writing it in a really archaic fa= shion.</div> <div><br></div><div>People ARE writing these logical constructs whether the= y use a clear logical expressions or not... why not just let them write it = between the parentheses in a clear and concise manner, than scatter and obs= cure the logic across 10 lines?</div> --20cf3005dee22f0cc204b6ac194f--
Jan 16 2012