www.digitalmars.com         C & C++   DMDScript  

D - version bites again ...

reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
I can't do the following:

int main(char[][] args)
{
    if( args.length > 1 &&
version(Windows)
{
        (   args[1][0] == '-' ||
            args[1][0] == '/') &&
}
else
{
        args[1][0] == '-' &&
}
        args[1][1] == '?')
    {
        usage();
    }

    return 0;
}

Is there no way that the braces for the version statement can be changed
such that they're not part of normal code syntax?

What about

int main(char[][] args)
{
    if( args.length > 1 &&
version(Windows)
[<
        (   args[1][0] == '-' ||
            args[1][0] == '/') &&
]

[< args[1][0] == '-' &&
]

{ usage(); } return 0; } or something similar. As it is I have to write it like: int main(char[][] args) { version(Windows) { if( args.length > 1 && ( args[1][0] == '-' || args[1][0] == '/') && args[1][1] == '?') { usage(); } } else { if( args.length > 1 && args[1][0] == '-' && args[1][1] == '?') { usage(); } } return 0; } which is positively giving the middle finger to the ODR. :( Matthew
Dec 18 2003
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Matthew wrote:

I can't do the following:

int main(char[][] args)
{
    if( args.length > 1 &&
version(Windows)
{
        (   args[1][0] == '-' ||
            args[1][0] == '/') &&
}
else
{
        args[1][0] == '-' &&
}
        args[1][1] == '?')
    {
        usage();
    }

    return 0;
}

Is there no way that the braces for the version statement can be changed
such that they're not part of normal code syntax?

Matthew

  

int main(char[][] args) { if(args.length > 1) version(Windows) { if(args[1][0] == '-' || args[1][0] == '/') } else { if (args[1][0] == '-') } if (args[1][1] == '?') { usage(); } } return 0; } You could do this: if( args.length > 1 && args[1][1] == '?') { if (args[1][0] == '-' ) { usage(); } else { version (Windows) { if (args[1][0] == '/') { usage(); } } } } But I know what you mean. -Anderson
Dec 18 2003
prev sibling next sibling parent reply Ant <Ant_member pathlink.com> writes:
In article <brt3su$1ejg$3 digitaldaemon.com>, Matthew says...
I can't do the following:

int main(char[][] args)
{
    if( args.length > 1 &&
version(Windows)
{
        (   args[1][0] == '-' ||
            args[1][0] == '/') &&
}
else
{
        args[1][0] == '-' &&
}
        args[1][1] == '?')
    {
        usage();
    }

    return 0;
}

Is there no way that the braces for the version statement can be changed
such that they're not part of normal code syntax?

What about

int main(char[][] args)
{
    if( args.length > 1 &&
version(Windows)
[<
        (   args[1][0] == '-' ||
            args[1][0] == '/') &&
]

[< args[1][0] == '-' &&
]

{ usage(); } return 0; } or something similar. As it is I have to write it like: int main(char[][] args) { version(Windows) { if( args.length > 1 && ( args[1][0] == '-' || args[1][0] == '/') && args[1][1] == '?') { usage(); } } else { if( args.length > 1 && args[1][0] == '-' && args[1][1] == '?') { usage(); } } return 0; } which is positively giving the middle finger to the ODR. :( Matthew

I would do it like this: ##################### module somewhere; version linux { bool isCommandLineSwitch... } else { //you get the idea... } ###################### module myApp; import somewhere; int main(char[][] args) { // see how much easy to understand this is? if ( args.length > 1 && somewhere.isCommandLineSwitch(args[1][0]) && args[1][1] = '?' ) { usage(); } } ############## In other words, beside other problems, you're doing a common test at the prog level instead of some lib level. maybe module somewhere could be part of phobos. maybe we can create another common sense rule: if the version doesn't fit your program probably your prog should be reviwed. (maybe not... ;) maybe you are right and just unlucky selecting the example... but I think giving that flexibility to version will make people abuse it and create unreadble, unmaintainable progs. Perheaps that is desirable(?). Ant PS after reading my post it sounds rude. Sorry I don't mean that, please forgive my limitation with English.
Dec 18 2003
parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
"Ant" <Ant_member pathlink.com> wrote in message
news:brt7ro$1kii$1 digitaldaemon.com...
 In article <brt3su$1ejg$3 digitaldaemon.com>, Matthew says...
I can't do the following:

int main(char[][] args)
{
    if( args.length > 1 &&
version(Windows)
{
        (   args[1][0] == '-' ||
            args[1][0] == '/') &&
}
else
{
        args[1][0] == '-' &&
}
        args[1][1] == '?')
    {
        usage();
    }

    return 0;
}

Is there no way that the braces for the version statement can be changed
such that they're not part of normal code syntax?

What about

int main(char[][] args)
{
    if( args.length > 1 &&
version(Windows)
[<
        (   args[1][0] == '-' ||
            args[1][0] == '/') &&
]

[< args[1][0] == '-' &&
]

{ usage(); } return 0; } or something similar. As it is I have to write it like: int main(char[][] args) { version(Windows) { if( args.length > 1 && ( args[1][0] == '-' || args[1][0] == '/') && args[1][1] == '?') { usage(); } } else { if( args.length > 1 && args[1][0] == '-' && args[1][1] == '?') { usage(); } } return 0; } which is positively giving the middle finger to the ODR. :( Matthew

I would do it like this: ##################### module somewhere; version linux { bool isCommandLineSwitch... } else { //you get the idea... } ###################### module myApp; import somewhere; int main(char[][] args) { // see how much easy to understand this is? if ( args.length > 1 && somewhere.isCommandLineSwitch(args[1][0]) && args[1][1] = '?' ) { usage(); } } ############## In other words, beside other problems, you're doing a common test at the prog level instead of some lib level.

Well, yeah, of course I've done it like that. ;) But there are going to be countless cases where using {} braces for version and for code is going to cause problems.
 maybe module somewhere could be part of phobos.

 maybe we can create another common sense rule:
 if the version doesn't fit your program probably
 your prog should be reviwed.
 (maybe not... ;)

 maybe you are right and just unlucky selecting the
 example...
 but I think giving that flexibility to version will
 make people abuse it and create unreadble, unmaintainable
 progs. Perheaps that is desirable(?).

 Ant
 PS after reading my post it sounds rude. Sorry I don't
 mean that, please forgive my limitation with English.

Duck. Back. Water. :)
Dec 18 2003
parent reply Ant <Ant_member pathlink.com> writes:
In article <brt88c$1l8c$2 digitaldaemon.com>, Matthew says...

 please forgive my limitation with English.

Duck. Back. Water. :)

(Just to remind everybody of the comunication dificulties on this multicultural thing) I have no idea what you mean so I tried google and got: "water off a duck’s back To fail to catch on or make a mark: “The reporter’s snide comments rolled off the candidate like water off a duck’s back.” " I can also get it like: Duck - someone is trying to hide Back - and run away Water - but hit the water = humiliation ???????? :) Ant
Dec 18 2003
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
 please forgive my limitation with English.

Duck. Back. Water. :)

(Just to remind everybody of the comunication dificulties on this multicultural thing) I have no idea what you mean so I tried google and got: "water off a duck's back To fail to catch on or make a mark: "The reporter's snide comments rolled

 the candidate like water off a duck's back." "

 I can also get it like:
 Duck - someone is trying to hide
 Back - and run away
 Water - but hit the water = humiliation

 ???????? :)

I wasn't implying you were snide. That quote's not the best. "Like water off a duck's back" is an English expression meaning that whatever discomfiture might be experienced can be borne with ease. In other words, you don't need to apologise about a potential small offence, as it won't bother me. (And I'm wont to offend in small ways myself. ;) Cheers Matthew
Dec 18 2003
prev sibling next sibling parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
Did you try:

int main (char[][] args)
{
     version(Windows) { if (
         args.length > 1
         && (args[1][0] == '-' || args[1][0] == '/')
         && args[1][1] == '?'
     )}
     else { if (
         args.length > 1
         && args[1][0] == '-'
         && args[1][1] == '?'
     )}
     {
         usage()
     }

     return 0;
}

Its not a thousand times better, but I think it should work.

-- C. Sauls
-- Invironz
Dec 18 2003
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
You'd need to have the usage() call within it, I think.

Short answer, no, I didn't.

:)

"C. Sauls" <ibisbasenji yahoo.com> wrote in message
news:brt7tj$1kmk$1 digitaldaemon.com...
 Did you try:

 int main (char[][] args)
 {
      version(Windows) { if (
          args.length > 1
          && (args[1][0] == '-' || args[1][0] == '/')
          && args[1][1] == '?'
      )}
      else { if (
          args.length > 1
          && args[1][0] == '-'
          && args[1][1] == '?'
      )}
      {
          usage()
      }

      return 0;
 }

 Its not a thousand times better, but I think it should work.

 -- C. Sauls
 -- Invironz

Dec 18 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Matthew" <matthew.hat stlsoft.dot.org> wrote in message
news:brt3su$1ejg$3 digitaldaemon.com...
 I can't do the following:

 int main(char[][] args)
 {
     if( args.length > 1 &&
 version(Windows)
 {
         (   args[1][0] == '-' ||
             args[1][0] == '/') &&
 }
 else
 {
         args[1][0] == '-' &&
 }
         args[1][1] == '?')
     {
         usage();
     }

     return 0;
 }

 Is there no way that the braces for the version statement can be changed
 such that they're not part of normal code syntax?

 What about

 int main(char[][] args)
 {
     if( args.length > 1 &&
 version(Windows)
 [<
         (   args[1][0] == '-' ||
             args[1][0] == '/') &&
]

[< args[1][0] == '-' &&
]

{ usage(); } return 0; } or something similar. As it is I have to write it like: int main(char[][] args) { version(Windows) { if( args.length > 1 && ( args[1][0] == '-' || args[1][0] == '/') && args[1][1] == '?') { usage(); } } else { if( args.length > 1 && args[1][0] == '-' && args[1][1] == '?') { usage(); } } return 0; } which is positively giving the middle finger to the ODR.

Frankly, I think the latter one is more readable than either of the former two examples. But I would write it as: int main(char[][] args) { if (args.length > 1) { switch (args[1]) { version (Windows) { case "/?": } case "-?": usage(); break; } } return 0; } To embed versions into expressions, you can write: bit slash = false; version (Windows) slash = true; // support slash style switches if (args.length > 1 && ((slash && args[1] == "/?") || args[1] == "-?")) Note that the optimizer will recognize that slash is a constant, and will optimize away that test and any dependent expressions on it that will never be evaluated.
Dec 18 2003