digitalmars.D - Version statement
- Extrawurst (11/11) Dec 14 2010 Hi i just want to discuss two points about D version statements.
- Jacob Carlborg (8/19) Dec 14 2010 That has been suggested many times before, If I recall correctly Walter
- Nick Sabalausky (43/61) Dec 14 2010 Not that I agree or disagree with this, but IIRC, the reason Walter gave...
- Walter Bright (8/11) Dec 14 2010 That particular problem has bitten me probably hundreds of times, and ev...
- Nick Sabalausky (7/19) Dec 14 2010 I can believe that.
- Andrei Alexandrescu (3/15) Dec 14 2010 svn diff and svn blame for the rescue :o).
- Walter Bright (12/21) Dec 14 2010 The idea is that versions should be positive statements, not some comple...
- Simen kjaeraas (5/9) Dec 14 2010 Likely something like __traits( versions ), that returns ["DigitalMars",
- Extrawurst (2/10) Dec 14 2010 Yes, exactly that.
- Walter Bright (2/18) Dec 14 2010 I suggest filing this as an enhancement request to bugzilla.
- Denis Koroskin (13/24) Dec 14 2010 Try using static if instead:
Hi i just want to discuss two points about D version statements. 1) Why is it not possible to negate the condition of a version statement. I think it is unintuitive and keeps me writing weird statements like: version(Win32){}else{version = NotWin32;} 2) I would really like the idea to be able to get a compiletime string of version identifiers in some kind of way. Perhaps even an array of version-strings. Any thoughts on that ? Regards, Stephan
Dec 14 2010
On 2010-12-14 19:46, Extrawurst wrote:Hi i just want to discuss two points about D version statements. 1) Why is it not possible to negate the condition of a version statement. I think it is unintuitive and keeps me writing weird statements like: version(Win32){}else{version = NotWin32;}That has been suggested many times before, If I recall correctly Walter doesn't like it. You could use bool constants and static if instead to get the behavior you want. It's ugly but it works, here you have most of the predefined version statements as bool constants: http://dsource.org/projects/dstep/browser/dstep/internal/Version.d2) I would really like the idea to be able to get a compiletime string of version identifiers in some kind of way. Perhaps even an array of version-strings. Any thoughts on that ? Regards, Stephan-- /Jacob Carlborg
Dec 14 2010
"Jacob Carlborg" <doob me.com> wrote in message news:ie8fdf$ol8$1 digitalmars.com...On 2010-12-14 19:46, Extrawurst wrote:Not that I agree or disagree with this, but IIRC, the reason Walter gave as to why he's against it is that he feels strongly that every platform you intend to support should be used explicitly so that other platforms don't appear to work by accident but then have bugs because something needs to be done differently. Ex: Suppose there are OSes: OS_A, OS_B, and OS_C, and you have code like this: version(OS_A) { void foo() { /* Code for OS_A */ } } else { void foo() { /* Code for OS_B and OS_C */ } } But now, when you or someone else comes along and compiles it for OS_D, it's going to silently use the code for OS_B and OS_C *regardless* of whether or not that's correct for OS_D. Maybe OS_D needs to use the code for OS_A. Or maybe it needs to use something completely different. But if you write it like this: version(OS_A) { void foo() { /* Code for OS_A */ } } version(OS_B) version = UseAlternateFoo; version(OS_C) version = UseAlternateFoo; version(UseAlternateFoo) { void foo() { /* Code for OS_B and OS_C */ } } Now, if you or someone else compiles for OS_D, you'll get an error that "foo()" is undefined (at least if "foo()" is actually used anywhere). This forces you to actually think about which foo() OS_D should use or if it should use an entitrely different one, instead of just randomly choosing one. So this is safer. Walter feels that disallowing "version( ! BLAH )" discourages the error-prone first style and encourages the safer second-style. Not everyone agrees though. I'm not quite sure how I feel about it.Hi i just want to discuss two points about D version statements. 1) Why is it not possible to negate the condition of a version statement. I think it is unintuitive and keeps me writing weird statements like: version(Win32){}else{version = NotWin32;}That has been suggested many times before, If I recall correctly Walter doesn't like it. You could use bool constants and static if instead to get the behavior you want. It's ugly but it works, here you have most of the predefined version statements as bool constants: http://dsource.org/projects/dstep/browser/dstep/internal/Version.dNothing that I know of, but there's been a lot of discussion about improvements that the version() system really, really needs. Unfortunately doesn't seem to be a high priority though.2) I would really like the idea to be able to get a compiletime string of version identifiers in some kind of way. Perhaps even an array of version-strings. Any thoughts on that ?
Dec 14 2010
Nick Sabalausky wrote:But now, when you or someone else comes along and compiles it for OS_D, it's going to silently use the code for OS_B and OS_C *regardless* of whether or not that's correct for OS_D.That particular problem has bitten me probably hundreds of times, and every other programmer as well. And it happens for lots of things besides OS versions. Though a programmer can always defeat the intent. At one point, someone added "support" for another OS in Phobos by copy/pasting the support declarations from another OS into the version block. Naturally, it was all wrong. The problem was I didn't know which parts were copy/pasted, so I had to go through every single declaration one at a time.
Dec 14 2010
"Walter Bright" <newshound2 digitalmars.com> wrote in message news:ie8j0d$1a95$1 digitalmars.com...Nick Sabalausky wrote:I can believe that.But now, when you or someone else comes along and compiles it for OS_D, it's going to silently use the code for OS_B and OS_C *regardless* of whether or not that's correct for OS_D.That particular problem has bitten me probably hundreds of times, and every other programmer as well. And it happens for lots of things besides OS versions.Though a programmer can always defeat the intent. At one point, someone added "support" for another OS in Phobos by copy/pasting the support declarations from another OS into the version block. Naturally, it was all wrong. The problem was I didn't know which parts were copy/pasted, so I had to go through every single declaration one at a time.A good comparison utility like Beyond Compare or Ultra Compare would have made that easy. I used Beyond Compare for the first time nearly ten years ago, and from that moment until this day it's one of those things, like a decent text editer, that I just couldn't do without.
Dec 14 2010
On 12/14/10 2:09 PM, Walter Bright wrote:Nick Sabalausky wrote:svn diff and svn blame for the rescue :o). AndreiBut now, when you or someone else comes along and compiles it for OS_D, it's going to silently use the code for OS_B and OS_C *regardless* of whether or not that's correct for OS_D.That particular problem has bitten me probably hundreds of times, and every other programmer as well. And it happens for lots of things besides OS versions. Though a programmer can always defeat the intent. At one point, someone added "support" for another OS in Phobos by copy/pasting the support declarations from another OS into the version block. Naturally, it was all wrong. The problem was I didn't know which parts were copy/pasted, so I had to go through every single declaration one at a time.
Dec 14 2010
Extrawurst wrote:Hi i just want to discuss two points about D version statements. 1) Why is it not possible to negate the condition of a version statement. I think it is unintuitive and keeps me writing weird statements like: version(Win32){}else{version = NotWin32;}The idea is that versions should be positive statements, not some complex formulation from other versions. The latter is commonplace in C, and in my experience nearly always wrong. For example, NotWin32 is, what? It's a bug waiting to happen. The preferred way is: version (Win32) ... else version (linux) ... else static assert(0, "unsupported system");2) I would really like the idea to be able to get a compiletime string of version identifiers in some kind of way. Perhaps even an array of version-strings.I don't know what that means.
Dec 14 2010
Walter Bright <newshound2 digitalmars.com> wrote:Likely something like __traits( versions ), that returns ["DigitalMars", "Windows", "X86", "LittleEndian", "D_InlineAsm_X86", "D_Version2", "all"]. -- Simen2) I would really like the idea to be able to get a compiletime string of version identifiers in some kind of way. Perhaps even an array of version-strings.I don't know what that means.
Dec 14 2010
On 14.12.2010 20:23, Simen kjaeraas wrote:Walter Bright <newshound2 digitalmars.com> wrote:Yes, exactly that.Likely something like __traits( versions ), that returns ["DigitalMars", "Windows", "X86", "LittleEndian", "D_InlineAsm_X86", "D_Version2", "all"].2) I would really like the idea to be able to get a compiletime string of version identifiers in some kind of way. Perhaps even an array of version-strings.I don't know what that means.
Dec 14 2010
Extrawurst wrote:On 14.12.2010 20:23, Simen kjaeraas wrote:I suggest filing this as an enhancement request to bugzilla.Walter Bright <newshound2 digitalmars.com> wrote:Yes, exactly that.Likely something like __traits( versions ), that returns ["DigitalMars", "Windows", "X86", "LittleEndian", "D_InlineAsm_X86", "D_Version2", "all"].2) I would really like the idea to be able to get a compiletime string of version identifiers in some kind of way. Perhaps even an array of version-strings.I don't know what that means.
Dec 14 2010
On Tue, 14 Dec 2010 21:46:47 +0300, Extrawurst <spam extrawurst.org> wrote:Hi i just want to discuss two points about D version statements. 1) Why is it not possible to negate the condition of a version statement. I think it is unintuitive and keeps me writing weird statements like: version(Win32){}else{version = NotWin32;} 2) I would really like the idea to be able to get a compiletime string of version identifiers in some kind of way. Perhaps even an array of version-strings. Any thoughts on that ? Regards, StephanTry using static if instead: version (Win32) { enum IsWin32 = true; } else { enum IsWin32 = false; } static if (IsWin32) { // ... } static if (!IsWin32) { // ... }
Dec 14 2010