View mode: basic / threaded / horizontal-split · Log in · Help
November 29, 2006
Re: minwin
Bill Baxter wrote:
> 
> Agreed.  'version' is basically just an emasculated special case of 
> 'static if'.  'static if' didn't exist when 'version' was created, but 
> now that it does, I think it would make more sense if version became a 
> kind of static if with access to a special version namespace.  'Windows' 
> should be treated like an alias for true if it is indeed defined, 
> otherwise false, and you should be allowed to do boolean ops with any 
> constant values in your program inside the version statement.
> 
> --bb

I dont think a version statement should be able to access anything but 
versions. besides that I agree!
November 29, 2006
Re: minwin
Bill Baxter wrote:
> Tomas Lindquist Olsen wrote:
>> Walter Bright wrote:
>>> Gregor Richards wrote:
>>>>>     version (NOTWINDOWS) => version (LINUX)
>>>> I hate to say this, but that example just plain stupid. All it will 
>>>> ever do is limit your code to work on only certain operating 
>>>> systems. That's hindering portability, and that's no good.
>>>>
>>>> As it turns out, it's often the case that such-and-such does work on 
>>>> every sane operating system, and therefore version (!Windows) makes 
>>>> sense.
>>>
>>> I've seen a lot of code that did that, and it was nearly always 
>>> broken. That's one motivation for operating system versions should be 
>>> positives, not "this is for not windows" or "this is for not linux". 
>>> Such fundamentally are wrong, and will bite you or the maintainer 
>>> sooner or later.
>>>
>>>> I know I've ran into instances where $WEIRD_SOCKET_FEATURE_X crashes 
>>>> horribly on a certain operating system, so I was forced to #ifndef 
>>>> __APPLE__. The same feature worked fine on literally every other 
>>>> system I tested it on, so it would be ridiculous to do an #ifdef for 
>>>> everything BUT Apple.
>>>>
>>>> version (darwin)
>>>> version (BSD)
>>>> version (Solaris)
>>>> version (SkyOS)
>>>> version (DJGPP)
>>>> version (HURD)
>>>> version (ObscureOS)
>>>> version (OSYetToBeInvented)
>>>
>>> What I'd do is have APPLE_SOCKET_BUG with the workaround, and the 
>>> default for the else. That way, you can search for the workarounds 
>>> for that bug, and they won't be confused with other apple features or 
>>> other apple bugs. Furthermore, if apple fixes that bug, you can 
>>> update your code much easier with a targeted update than if you 
>>> painted the entire apple os that way.
>>>
>>> It's common practice (such as in STL) to target specific bugs with 
>>> specific identifiers, and then have a configuration file which sets 
>>> up the bugs for each system.
>>>
>>>> Thinking in positives is great, but so unrealistic as to be 
>>>> completely valueless. version statements in reality are used like 
>>>> indexes into sets. The set of operating systems, the set of C 
>>>> libraries, the set of compielrs. And it's unrealistic and ignorant 
>>>> to try to index EVERY member except for whichever one you like, 
>>>> especially since the list is always growing.
>>>>
>>>> Not everything has a positive opposite. In fact, most everything 
>>>> doesn't.
>>>
>>> I don't agree, and as an example I suggest the socket bug approach 
>>> above.
>>
>> This discussion has made me remember something I though about a while 
>> ago...
>> While I understand the reasoning for disallowing negated version 
>> identifiers / version statements from the above, I dont understand why 
>> we can't use logical operators with versions:
>>
>> version(Windows)
>> {
>>     writefln("I know your OS");
>> }
>> else version(linux)
>> {
>>     writefln("I know your OS");
>> }
>> else version(darwin)
>> {
>>     writefln("I know your OS");
>> }
>> else
>> {
>>     writefln("I don't know your OS");
>> }
>>
>> VS.
>>
>> version(Windows || linux || darwin)
>> {
>>     writefln("I know your OS");
>> }
>> else
>> {
>>     writefln("I don't know your OS");
>> }
>>
>> This genuinely reduces code duplication and is thus according to 
>> standard D mentality: less prone to be buggy, easier to maintain, and 
>> faster to write.
>> Though if something like this was to be allowed, && and ! probably 
>> should be as well.
>> IIRC the reason I wanted something like this was for a demo where I 
>> use a proprietary library that only supports win32 and linux, and thus 
>> those two versions wants a single implementation, all other will not 
>> use it at all.
>>
>> I realise this can be done with something like:
>>
>> version(Windows) version=OK;
>> else version(linux) version=OK;
>> version(OK)
>> {
>>     ...
>> }
>> else
>> {
>>     ...
>> }
>>
>> but just:
>>
>> version(Windows || linux)
>> {
>>     ...
>> }
>> else
>> {
>>     ...
>> }
>>
>> is clearer IMHO.
> 
> 
> Agreed.  'version' is basically just an emasculated special case of 
> 'static if'.  'static if' didn't exist when 'version' was created, but 
> now that it does, I think it would make more sense if version became a 
> kind of static if with access to a special version namespace.  'Windows' 
> should be treated like an alias for true if it is indeed defined, 
> otherwise false, and you should be allowed to do boolean ops with any 
> constant values in your program inside the version statement.
> 
> --bb

I know we've been over this before, but the suggested syntax is clearly 
more elegant than the current use. Could you specify any particular 
reason why these operators shouldn't be allowed in this manner?

However, I also dont agree that anything other than Versions should work 
inside of version() expressions.
November 29, 2006
Re: minwin
Tomas Lindquist Olsen wrote:
> Hi folks.
> Just want to tell people that I have uploaded a zip with a MinWin that 
> builds on DMD 0.175.
> 
> Check it at:
> http://wiki.dprogramming.com/MinWin/HomePage
> 
> it only really took fixing the private/public import changes but it was 
> boring and I figure someone else might like to avoid it...
> 
> - lindquist

For those that dont read the dsource forums, Brad has set up a SVN 
repository [1] and Trac environment [2] for MinWin and given me admin 
rights.

I have committed the version I posted to SVN with Anders's patch applied.

Lets get MinWin back on track :)

If there's anything let me know. I wont be the most active developer 
from day 1, I still need to read alot of the source + understand it, 
etc, but I will do my best to administer the project. At least now it 
can move on...

------------------------

[1] : http://svn.dsource.org/projects/minwin/trunk/minwin
[2] : http://www.dsource.org/projects/minwin/wiki
November 29, 2006
Re: minwin
Tomas Lindquist Olsen wrote:
> Bill Baxter wrote:
>>
>> Agreed.  'version' is basically just an emasculated special case of 
>> 'static if'.  'static if' didn't exist when 'version' was created, but 
>> now that it does, I think it would make more sense if version became a 
>> kind of static if with access to a special version namespace.  
>> 'Windows' should be treated like an alias for true if it is indeed 
>> defined, otherwise false, and you should be allowed to do boolean ops 
>> with any constant values in your program inside the version statement.
>>
>> --bb
> 
> I dont think a version statement should be able to access anything but 
> versions. besides that I agree!

I could agree with only versions in version statements, but if so then 
there needs to be a way to define new versions from code.

Walter's comment about defining versions for specific bugs is on target, 
but it makes no sense to have to specify every possible bug and 
workaround on the command line.  The common pattern used in most major 
cross-platform toolkits that deal with these issues is to have some sort 
of platform include that basically does things like:

#ifdef WINDOWS
#define BROKEN_PIPE_IMPLEMENTATION
#define BROKEN_SELECT_IMPLEMENTATION
...etc
#endif

If version acted like an enhanced static if then you could do something 
like:

version (Windows) {
   const int BROKEN_THIS = 1;
   const int BROKEN_THAT = 1;
   ...
}

version (BROKEN_THIS) {
   // workaround code
}

In that case I guess version(/undefined symbol/) should evaluate to false.

If you can't use const ints in version statements, then I think you 
really need to have something like:

defversion BROKEN_THIS;
defversion BROKEN_THAT;

And while we're talking about versions, there also needs to be a sane 
way to check if the version of the software you're using is greater than 
some minimum.

version(COOL_LIB_MAJOR_REV>4 || (COOL_LIB_MINOR_REV > 1)
{
}

or even better something special for version numbers like or

version(COOL_LIB_REV > [4, 1])

version(COOL_LIB_REV > 4.1.0)

Here's wxWidgets version macro for checking the version of wxWidgets 
you're compiling with.  It should be possible to get the same effect in 
D somehow:

/*  check if the current version is at least major.minor.release */
#define wxCHECK_VERSION(major,minor,release) \
    (wxMAJOR_VERSION > (major) || \
    (wxMAJOR_VERSION == (major) && wxMINOR_VERSION > (minor)) || \
    (wxMAJOR_VERSION == (major) && wxMINOR_VERSION == (minor) && 
wxRELEASE_NUMBER >= (release)))

Here's the full header that came from:  http://tinyurl.com/tzbom


Basically I think you can do all that with static if now.  If version 
doesn't get some more smarts then I'm betting people will use static if 
to accomplish things like the above since it's the only way.  And if 
people start using static if for version checks, well then what was the 
point of version, exactly?

--bb
November 29, 2006
Re: minwin
Bill Baxter wrote:
> Tomas Lindquist Olsen wrote:
>> Bill Baxter wrote:
>>>
>>> Agreed.  'version' is basically just an emasculated special case of 
>>> 'static if'.  'static if' didn't exist when 'version' was created, 
>>> but now that it does, I think it would make more sense if version 
>>> became a kind of static if with access to a special version 
>>> namespace.  'Windows' should be treated like an alias for true if it 
>>> is indeed defined, otherwise false, and you should be allowed to do 
>>> boolean ops with any constant values in your program inside the 
>>> version statement.
>>>
>>> --bb
>>
>> I dont think a version statement should be able to access anything but 
>> versions. besides that I agree!
> 
> I could agree with only versions in version statements, but if so then 
> there needs to be a way to define new versions from code.
> 
> Walter's comment about defining versions for specific bugs is on target, 
> but it makes no sense to have to specify every possible bug and 
> workaround on the command line.  The common pattern used in most major 
> cross-platform toolkits that deal with these issues is to have some sort 
> of platform include that basically does things like:
> 
> #ifdef WINDOWS
> #define BROKEN_PIPE_IMPLEMENTATION
> #define BROKEN_SELECT_IMPLEMENTATION
> ...etc
> #endif
> 
> If version acted like an enhanced static if then you could do something 
> like:
> 
> version (Windows) {
>    const int BROKEN_THIS = 1;
>    const int BROKEN_THAT = 1;
>    ...
> }
> 
> version (BROKEN_THIS) {
>    // workaround code
> }
> 
> In that case I guess version(/undefined symbol/) should evaluate to false.
> 
> If you can't use const ints in version statements, then I think you 
> really need to have something like:
> 
> defversion BROKEN_THIS;
> defversion BROKEN_THAT;
> 
> And while we're talking about versions, there also needs to be a sane 
> way to check if the version of the software you're using is greater than 
> some minimum.
> 
> version(COOL_LIB_MAJOR_REV>4 || (COOL_LIB_MINOR_REV > 1)
> {
> }
> 
> or even better something special for version numbers like or
> 
> version(COOL_LIB_REV > [4, 1])
> 
> version(COOL_LIB_REV > 4.1.0)
> 
> Here's wxWidgets version macro for checking the version of wxWidgets 
> you're compiling with.  It should be possible to get the same effect in 
> D somehow:
> 
> /*  check if the current version is at least major.minor.release */
> #define wxCHECK_VERSION(major,minor,release) \
>     (wxMAJOR_VERSION > (major) || \
>     (wxMAJOR_VERSION == (major) && wxMINOR_VERSION > (minor)) || \
>     (wxMAJOR_VERSION == (major) && wxMINOR_VERSION == (minor) && 
> wxRELEASE_NUMBER >= (release)))
> 
> Here's the full header that came from:  http://tinyurl.com/tzbom
> 
> 
> Basically I think you can do all that with static if now.  If version 
> doesn't get some more smarts then I'm betting people will use static if 
> to accomplish things like the above since it's the only way.  And if 
> people start using static if for version checks, well then what was the 
> point of version, exactly?
> 
> --bb

Read http://digitalmars.com/d/version.html#version : Version Specification
November 29, 2006
Re: minwin
> version (Windows) {
>    const int BROKEN_THIS = 1;
>    const int BROKEN_THAT = 1;
>    ...
> }
> 
> version (BROKEN_THIS) {
>    // workaround code
> }

Try:

version (Windows) {
    version = BROKEN_THIS;
    version = BROKEN_THAT;
}

version (BROKEN_THIS) {
    // work around code
}
November 29, 2006
Re: minwin
Tomas Lindquist Olsen wrote:

> Read http://digitalmars.com/d/version.html#version : Version Specification

Thanks. :-)

But I don't see how I specify that I want MY_COOL_LIB_VER > 010205.
I can only say I want 'version' to be >= 010205.  But version of what?

For checking versions of specific libs , and for defining new versions 
contingent on existing versions, it still looks like I need a static if.

--bb
November 29, 2006
Re: minwin
Brad Roberts wrote:
>> version (Windows) {
>>    const int BROKEN_THIS = 1;
>>    const int BROKEN_THAT = 1;
>>    ...
>> }
>>
>> version (BROKEN_THIS) {
>>    // workaround code
>> }
> 
> Try:
> 
> version (Windows) {
>     version = BROKEN_THIS;
>     version = BROKEN_THAT;
> }
> 
> version (BROKEN_THIS) {
>     // work around code
> }

Doh, ok.  Missed that.  Cool.

What about the check for specific version of lib?

--bb
November 29, 2006
Re: minwin
Bill Baxter wrote:
> Tomas Lindquist Olsen wrote:
> 
>> Read http://digitalmars.com/d/version.html#version : Version 
>> Specification
> 
> Thanks. :-)
> 
> But I don't see how I specify that I want MY_COOL_LIB_VER > 010205.
> I can only say I want 'version' to be >= 010205.  But version of what?
> 
> For checking versions of specific libs , and for defining new versions 
> contingent on existing versions, it still looks like I need a static if.
> 
> --bb
I really think you're leaving the scope of version now and entering 
if/static if
November 29, 2006
Re: minwin (combining version & static if)
Tomas Lindquist Olsen schrieb am 2006-11-29:
> Bill Baxter wrote:
>> Tomas Lindquist Olsen wrote:
>> 
>>> Read http://digitalmars.com/d/version.html#version : Version 
>>> Specification
>> 
>> Thanks. :-)
>> 
>> But I don't see how I specify that I want MY_COOL_LIB_VER > 010205.
>> I can only say I want 'version' to be >= 010205.  But version of what?
>> 
>> For checking versions of specific libs , and for defining new versions 
>> contingent on existing versions, it still looks like I need a static if.
>> 
>> --bb
> I really think you're leaving the scope of version now and entering 
> if/static if

You can combine both.

config.d:
#
# version(Windows){
#	const int WAPI_FEATURE = 3;
# }
#

some_code.d:
#
# import config;
#
# static if(is(typeof(WAPI_FEATURE)) && WAPI_FEATURE == 3){
# 	// ...
# }
#

Thomas
1 2 3 4 5 6 7
Top | Discussion index | About this forum | D home