www.digitalmars.com         C & C++   DMDScript  

D - Bring back #define

reply "Matthew Wilson" <matthew stlsoft.org> writes:
version(Windows)
{
            recls_assert(0 == strcmp(path + 2, pathCheck));
            if(0 != strcmp(path + 2, pathCheck))
}  <== HERE
else
{
            recls_assert(0 == strcmp(path, pathCheck));
            if(0 != strcmp(path, pathCheck))
}
            {
                fprintf(stderr, "Path is different from path
components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);

                abort();
            }


This does not compile. Understandably, the compiler doesn't like the brace
indicated. What are my options? Do I have to include the body of the if
statement twice? That doesn't help maintainability, does it?

I think version should either use a different brace, or should use a
different format altogether. Otherwise we'll be decreasing maintainability,
rather than increasing it.

Harummpphh!
Oct 10 2003
next sibling parent reply "Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> writes:
"Matthew Wilson" <matthew stlsoft.org> escreveu na mensagem
news:bm60qd$30eh$1 digitaldaemon.com...
 version(Windows)
 {
             recls_assert(0 == strcmp(path + 2, pathCheck));
             if(0 != strcmp(path + 2, pathCheck))
 }  <== HERE
 else
 {
             recls_assert(0 == strcmp(path, pathCheck));
             if(0 != strcmp(path, pathCheck))
 }
             {
                 fprintf(stderr, "Path is different from path
 components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);

                 abort();
             }


 This does not compile. Understandably, the compiler doesn't like the brace
 indicated. What are my options? Do I have to include the body of the if
 statement twice? That doesn't help maintainability, does it?

 I think version should either use a different brace, or should use a
 different format altogether. Otherwise we'll be decreasing
maintainability,
 rather than increasing it.

 Harummpphh!
Why don't you just write: path2 = path; version(Windows) { path2 = path2 + 2; } recls_assert(0 == strcmp(path2, pathCheck)); if(0 != strcmp(path2, pathCheck)) { fprintf(stderr, "Path is different from path components\n\tpath: %.*s\n\tparts: %.*s\n\n", path, pathCheck); abort(); } It'll remove the duplicated code and do what it's supposed to do. When I saw your example the first thing in my head was "why the code is duplicated, there must be another difference besides the '+ 2'." so I read the code carefully and discovered it was ok. If I was the maintainance programmer I would question that. IME it's better to reduce the differences to the absolute minimum, so it'll be clear what must be equal and what must be different. Best regards, Daniel Yokomiso. "The difference between me and the other surrealists is that I'm a surrealist." - Dali --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.524 / Virus Database: 321 - Release Date: 7/10/2003
Oct 10 2003
parent reply "Matthew Wilson" <matthew stlsoft.org> writes:
Yeah, that was not the best example. But that doesn't detract from the
general thrust of my argument. If the version-dependent code is not cleanly
outside a { } scope, then it breaks. Which sucks, and is unnecessarily
restrictive

"Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> wrote in message
news:bm62lk$18a$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> escreveu na mensagem
 news:bm60qd$30eh$1 digitaldaemon.com...
 version(Windows)
 {
             recls_assert(0 == strcmp(path + 2, pathCheck));
             if(0 != strcmp(path + 2, pathCheck))
 }  <== HERE
 else
 {
             recls_assert(0 == strcmp(path, pathCheck));
             if(0 != strcmp(path, pathCheck))
 }
             {
                 fprintf(stderr, "Path is different from path
 components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);

                 abort();
             }


 This does not compile. Understandably, the compiler doesn't like the
brace
 indicated. What are my options? Do I have to include the body of the if
 statement twice? That doesn't help maintainability, does it?

 I think version should either use a different brace, or should use a
 different format altogether. Otherwise we'll be decreasing
maintainability,
 rather than increasing it.

 Harummpphh!
Why don't you just write: path2 = path; version(Windows) { path2 = path2 + 2; } recls_assert(0 == strcmp(path2, pathCheck)); if(0 != strcmp(path2, pathCheck)) { fprintf(stderr, "Path is different from path components\n\tpath: %.*s\n\tparts: %.*s\n\n", path, pathCheck); abort(); } It'll remove the duplicated code and do what it's supposed to do. When I
saw
 your example the first thing in my head was "why the code is duplicated,
 there must be another difference besides the '+ 2'." so I read the code
 carefully and discovered it was ok. If I was the maintainance programmer I
 would question that. IME it's better to reduce the differences to the
 absolute minimum, so it'll be clear what must be equal and what must be
 different.

 Best regards,
 Daniel Yokomiso.

 "The difference between me and the other surrealists is that I'm a
 surrealist."
  - Dali


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.524 / Virus Database: 321 - Release Date: 7/10/2003
Oct 10 2003
parent reply "Jan-Eric Duden" <jeduden whisset.com> writes:
I guess we  need to get rid of our old "macro" habbits and rethink. :)
Or do you have a problem where version won't work at all?

-- 
Jan-Eric Duden
"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bm64m2$3ue$1 digitaldaemon.com...
 Yeah, that was not the best example. But that doesn't detract from the
 general thrust of my argument. If the version-dependent code is not
cleanly
 outside a { } scope, then it breaks. Which sucks, and is unnecessarily
 restrictive

 "Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> wrote in message
 news:bm62lk$18a$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> escreveu na mensagem
 news:bm60qd$30eh$1 digitaldaemon.com...
 version(Windows)
 {
             recls_assert(0 == strcmp(path + 2, pathCheck));
             if(0 != strcmp(path + 2, pathCheck))
 }  <== HERE
 else
 {
             recls_assert(0 == strcmp(path, pathCheck));
             if(0 != strcmp(path, pathCheck))
 }
             {
                 fprintf(stderr, "Path is different from path
 components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);

                 abort();
             }


 This does not compile. Understandably, the compiler doesn't like the
brace
 indicated. What are my options? Do I have to include the body of the
if
 statement twice? That doesn't help maintainability, does it?

 I think version should either use a different brace, or should use a
 different format altogether. Otherwise we'll be decreasing
maintainability,
 rather than increasing it.

 Harummpphh!
Why don't you just write: path2 = path; version(Windows) { path2 = path2 + 2; } recls_assert(0 == strcmp(path2, pathCheck)); if(0 != strcmp(path2, pathCheck)) { fprintf(stderr, "Path is different from path components\n\tpath: %.*s\n\tparts: %.*s\n\n", path, pathCheck); abort(); } It'll remove the duplicated code and do what it's supposed to do. When I
saw
 your example the first thing in my head was "why the code is duplicated,
 there must be another difference besides the '+ 2'." so I read the code
 carefully and discovered it was ok. If I was the maintainance programmer
I
 would question that. IME it's better to reduce the differences to the
 absolute minimum, so it'll be clear what must be equal and what must be
 different.

 Best regards,
 Daniel Yokomiso.

 "The difference between me and the other surrealists is that I'm a
 surrealist."
  - Dali


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.524 / Virus Database: 321 - Release Date: 7/10/2003
Oct 10 2003
next sibling parent reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
"Jan-Eric Duden" <jeduden whisset.com> wrote in message
news:bm65lf$58d$1 digitaldaemon.com...
 I guess we  need to get rid of our old "macro" habbits and rethink. :)
 Or do you have a problem where version won't work at all?
Converting header files to D. If they are large and need different calling conventions on different platforms (like OpenGL), you need to write all the declarations twice. (Unless Walter make it possible to alias the calling conventions. Then I could put just the alias in a version statement.) Lars Ivar Igesund
Oct 10 2003
next sibling parent "Walter" <walter digitalmars.com> writes:
"Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
news:bm6lp2$qnl$1 digitaldaemon.com...
 "Jan-Eric Duden" <jeduden whisset.com> wrote in message
 news:bm65lf$58d$1 digitaldaemon.com...
 I guess we  need to get rid of our old "macro" habbits and rethink. :)
 Or do you have a problem where version won't work at all?
Converting header files to D. If they are large and need different calling conventions on different platforms (like OpenGL), you need to write all the declarations twice. (Unless Walter make it possible to alias the calling conventions. Then I could put just the alias in a version statement.)
That is a problem I need to address.
Oct 10 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
news:bm6lp2$qnl$1 digitaldaemon.com...
 Converting header files to D. If they are large and need different
 calling conventions on different platforms (like OpenGL), you need
 to write all the declarations twice. (Unless Walter make it possible
 to alias the calling conventions. Then I could put just the alias in a
 version statement.)
How about this: version (Foo) { extern (C): } version (Bar) { extern (Windows): } void abc(); void def(); ...
Oct 11 2003
next sibling parent "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bm9ree$2468$2 digitaldaemon.com...
 "Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
 news:bm6lp2$qnl$1 digitaldaemon.com...
 Converting header files to D. If they are large and need different
 calling conventions on different platforms (like OpenGL), you need
 to write all the declarations twice. (Unless Walter make it possible
 to alias the calling conventions. Then I could put just the alias in a
 version statement.)
How about this: version (Foo) { extern (C): } version (Bar) { extern (Windows): } void abc(); void def(); ...
Looks ok to me. I'll test it some other day. Lars Ivar Igesund
Oct 11 2003
prev sibling parent shinichiro.h <s31552 mail.ecc.u-tokyo.ac.jp> writes:
 How about this:
 
 version (Foo)
 {
     extern (C):
 }
 version (Bar)
 {
     extern (Windows):
 }
 
 void abc();
 void def();
 ...
Does it work good? I performed a simple following experiment:
 cat version.d
version (C) { extern(C): void c_func() {} } // I think "extern (C)" is ended. void maybe_not_c_func() {}
 dmd -c version.d
 nm version.o
00000000 ? _D7version16maybe_not_c_funcFZv 00000000 t gcc2_compiled.
 dmd -c -version=C version.d
 nm version.o
00000000 ? _D7version16maybe_not_c_funcFZv 00000000 ? c_func 00000000 t gcc2_compiled. I hope the last maybe_not_c_func has C-linkage, but it has D-linkage in my environment (Linux, DMD-0.73). ------------------ shinichiro.h s31552 mail.ecc.u-tokyo.ac.jp
Oct 12 2003
prev sibling next sibling parent reply "Matthew Wilson" <matthew stlsoft.org> writes:
No, but consider this, latest, one:

            char[]  composite_path1 =   null
version(Windows)
{
                                    ~   Drive()
} // version(Windows)
                                    ~   Directory()
                                    ~   File()
                                    ;

No-one can tell me that this would be better written as

version(Windows)
{
            char[]  composite_path1 =   null
                                    ~   Drive()
                                    ~   Directory()
                                    ~   File()
                                    ;
}
else
{
            char[]  composite_path1 =   null
                                    ~   Directory()
                                    ~   File()
                                    ;
} // version(Windows)

Now I have to write it as

            char[]  composite_path1 =   null;
version(Windows)
{
                    composite_path1 ~=  Drive();
} // version(Windows)
                    composite_path1 ~=  Directory();
                    composite_path1 ~=  File();

While this may be fine in the current context - inside an invariant - it
would be undesirable in release code. Maybe repeated ~= are less efficient
that a single ~, as they are in some other languages. Even if they're not, I
disagree that this repression of expressiveness is a good thing, just
because it is easier to implement the language feature in this way.



"Jan-Eric Duden" <jeduden whisset.com> wrote in message
news:bm65lf$58d$1 digitaldaemon.com...
 I guess we  need to get rid of our old "macro" habbits and rethink. :)
 Or do you have a problem where version won't work at all?

 -- 
 Jan-Eric Duden
 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bm64m2$3ue$1 digitaldaemon.com...
 Yeah, that was not the best example. But that doesn't detract from the
 general thrust of my argument. If the version-dependent code is not
cleanly
 outside a { } scope, then it breaks. Which sucks, and is unnecessarily
 restrictive

 "Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> wrote in message
 news:bm62lk$18a$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> escreveu na mensagem
 news:bm60qd$30eh$1 digitaldaemon.com...
 version(Windows)
 {
             recls_assert(0 == strcmp(path + 2, pathCheck));
             if(0 != strcmp(path + 2, pathCheck))
 }  <== HERE
 else
 {
             recls_assert(0 == strcmp(path, pathCheck));
             if(0 != strcmp(path, pathCheck))
 }
             {
                 fprintf(stderr, "Path is different from path
 components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);

                 abort();
             }


 This does not compile. Understandably, the compiler doesn't like the
brace
 indicated. What are my options? Do I have to include the body of the
if
 statement twice? That doesn't help maintainability, does it?

 I think version should either use a different brace, or should use a
 different format altogether. Otherwise we'll be decreasing
maintainability,
 rather than increasing it.

 Harummpphh!
Why don't you just write: path2 = path; version(Windows) { path2 = path2 + 2; } recls_assert(0 == strcmp(path2, pathCheck)); if(0 != strcmp(path2, pathCheck)) { fprintf(stderr, "Path is different from path components\n\tpath: %.*s\n\tparts: %.*s\n\n", path, pathCheck); abort(); } It'll remove the duplicated code and do what it's supposed to do. When
I
 saw
 your example the first thing in my head was "why the code is duplicate
d,
 there must be another difference besides the '+ 2'." so I read the
code
 carefully and discovered it was ok. If I was the maintainance
programmer
 I
 would question that. IME it's better to reduce the differences to the
 absolute minimum, so it'll be clear what must be equal and what must
be
 different.

 Best regards,
 Daniel Yokomiso.

 "The difference between me and the other surrealists is that I'm a
 surrealist."
  - Dali


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.524 / Virus Database: 321 - Release Date: 7/10/2003
Oct 10 2003
parent reply "Walter" <walter digitalmars.com> writes:
You could also write:

version (Windows)
{
    char[] Drive();
}
else
{
    char[] Drive() { return ""; }
}

"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bm7k39$244a$1 digitaldaemon.com...
 No, but consider this, latest, one:

             char[]  composite_path1 =   null
 version(Windows)
 {
                                     ~   Drive()
 } // version(Windows)
                                     ~   Directory()
                                     ~   File()
                                     ;

 No-one can tell me that this would be better written as

 version(Windows)
 {
             char[]  composite_path1 =   null
                                     ~   Drive()
                                     ~   Directory()
                                     ~   File()
                                     ;
 }
 else
 {
             char[]  composite_path1 =   null
                                     ~   Directory()
                                     ~   File()
                                     ;
 } // version(Windows)

 Now I have to write it as

             char[]  composite_path1 =   null;
 version(Windows)
 {
                     composite_path1 ~=  Drive();
 } // version(Windows)
                     composite_path1 ~=  Directory();
                     composite_path1 ~=  File();

 While this may be fine in the current context - inside an invariant - it
 would be undesirable in release code. Maybe repeated ~= are less efficient
 that a single ~, as they are in some other languages. Even if they're not,
I
 disagree that this repression of expressiveness is a good thing, just
 because it is easier to implement the language feature in this way.



 "Jan-Eric Duden" <jeduden whisset.com> wrote in message
 news:bm65lf$58d$1 digitaldaemon.com...
 I guess we  need to get rid of our old "macro" habbits and rethink. :)
 Or do you have a problem where version won't work at all?

 --
 Jan-Eric Duden
 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bm64m2$3ue$1 digitaldaemon.com...
 Yeah, that was not the best example. But that doesn't detract from the
 general thrust of my argument. If the version-dependent code is not
cleanly
 outside a { } scope, then it breaks. Which sucks, and is unnecessarily
 restrictive

 "Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> wrote in message
 news:bm62lk$18a$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> escreveu na mensagem
 news:bm60qd$30eh$1 digitaldaemon.com...
 version(Windows)
 {
             recls_assert(0 == strcmp(path + 2, pathCheck));
             if(0 != strcmp(path + 2, pathCheck))
 }  <== HERE
 else
 {
             recls_assert(0 == strcmp(path, pathCheck));
             if(0 != strcmp(path, pathCheck))
 }
             {
                 fprintf(stderr, "Path is different from path
 components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);

                 abort();
             }


 This does not compile. Understandably, the compiler doesn't like
the
 brace
 indicated. What are my options? Do I have to include the body of
the
 if
 statement twice? That doesn't help maintainability, does it?

 I think version should either use a different brace, or should use
a
 different format altogether. Otherwise we'll be decreasing
maintainability,
 rather than increasing it.

 Harummpphh!
Why don't you just write: path2 = path; version(Windows) { path2 = path2 + 2; } recls_assert(0 == strcmp(path2, pathCheck)); if(0 != strcmp(path2, pathCheck)) { fprintf(stderr, "Path is different from path components\n\tpath: %.*s\n\tparts: %.*s\n\n", path, pathCheck); abort(); } It'll remove the duplicated code and do what it's supposed to do.
When
 I
 saw
 your example the first thing in my head was "why the code is
duplicate
 d,
 there must be another difference besides the '+ 2'." so I read the
code
 carefully and discovered it was ok. If I was the maintainance
programmer
 I
 would question that. IME it's better to reduce the differences to
the
 absolute minimum, so it'll be clear what must be equal and what must
be
 different.

 Best regards,
 Daniel Yokomiso.

 "The difference between me and the other surrealists is that I'm a
 surrealist."
  - Dali


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.524 / Virus Database: 321 - Release Date: 7/10/2003
Oct 11 2003
parent reply "Matthew Wilson" <matthew stlsoft.org> writes:
No! On operating systems that do not have a drive, it is absolutely bogus
and evil to give them a "null" drive.

(btw, Drive returns a char, not a string)

Anyway, that's just the specific case. This will come up time and time
again, probably almost as much as #define is used, so we need something that
works.

"Walter" <walter digitalmars.com> wrote in message
news:bm9ref$2468$3 digitaldaemon.com...
 You could also write:

 version (Windows)
 {
     char[] Drive();
 }
 else
 {
     char[] Drive() { return ""; }
 }

 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bm7k39$244a$1 digitaldaemon.com...
 No, but consider this, latest, one:

             char[]  composite_path1 =   null
 version(Windows)
 {
                                     ~   Drive()
 } // version(Windows)
                                     ~   Directory()
                                     ~   File()
                                     ;

 No-one can tell me that this would be better written as

 version(Windows)
 {
             char[]  composite_path1 =   null
                                     ~   Drive()
                                     ~   Directory()
                                     ~   File()
                                     ;
 }
 else
 {
             char[]  composite_path1 =   null
                                     ~   Directory()
                                     ~   File()
                                     ;
 } // version(Windows)

 Now I have to write it as

             char[]  composite_path1 =   null;
 version(Windows)
 {
                     composite_path1 ~=  Drive();
 } // version(Windows)
                     composite_path1 ~=  Directory();
                     composite_path1 ~=  File();

 While this may be fine in the current context - inside an invariant - it
 would be undesirable in release code. Maybe repeated ~= are less
efficient
 that a single ~, as they are in some other languages. Even if they're
not,
 I
 disagree that this repression of expressiveness is a good thing, just
 because it is easier to implement the language feature in this way.



 "Jan-Eric Duden" <jeduden whisset.com> wrote in message
 news:bm65lf$58d$1 digitaldaemon.com...
 I guess we  need to get rid of our old "macro" habbits and rethink. :)
 Or do you have a problem where version won't work at all?

 --
 Jan-Eric Duden
 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bm64m2$3ue$1 digitaldaemon.com...
 Yeah, that was not the best example. But that doesn't detract from
the
 general thrust of my argument. If the version-dependent code is not
cleanly
 outside a { } scope, then it breaks. Which sucks, and is
unnecessarily
 restrictive

 "Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> wrote in message
 news:bm62lk$18a$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> escreveu na mensagem
 news:bm60qd$30eh$1 digitaldaemon.com...
 version(Windows)
 {
             recls_assert(0 == strcmp(path + 2, pathCheck));
             if(0 != strcmp(path + 2, pathCheck))
 }  <== HERE
 else
 {
             recls_assert(0 == strcmp(path, pathCheck));
             if(0 != strcmp(path, pathCheck))
 }
             {
                 fprintf(stderr, "Path is different from path
 components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);

                 abort();
             }


 This does not compile. Understandably, the compiler doesn't like
the
 brace
 indicated. What are my options? Do I have to include the body of
the
 if
 statement twice? That doesn't help maintainability, does it?

 I think version should either use a different brace, or should
use
 a
 different format altogether. Otherwise we'll be decreasing
maintainability,
 rather than increasing it.

 Harummpphh!
Why don't you just write: path2 = path; version(Windows) { path2 = path2 + 2; } recls_assert(0 == strcmp(path2, pathCheck)); if(0 != strcmp(path2, pathCheck)) { fprintf(stderr, "Path is different from path components\n\tpath: %.*s\n\tparts: %.*s\n\n", path, pathCheck); abort(); } It'll remove the duplicated code and do what it's supposed to do.
When
 I
 saw
 your example the first thing in my head was "why the code is
duplicate
 d,
 there must be another difference besides the '+ 2'." so I read the
code
 carefully and discovered it was ok. If I was the maintainance
programmer
 I
 would question that. IME it's better to reduce the differences to
the
 absolute minimum, so it'll be clear what must be equal and what
must
 be
 different.

 Best regards,
 Daniel Yokomiso.

 "The difference between me and the other surrealists is that I'm a
 surrealist."
  - Dali


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.524 / Virus Database: 321 - Release Date: 7/10/2003
Oct 11 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bm9sds$25dr$1 digitaldaemon.com...
 No! On operating systems that do not have a drive, it is absolutely bogus
 and evil to give them a "null" drive.

 (btw, Drive returns a char, not a string)

 Anyway, that's just the specific case. This will come up time and time
 again, probably almost as much as #define is used, so we need something
that
 works.
I know what you mean. Where I'm coming from is that I have dealt a lot with code that had lots of deeply embedded #ifdef's in it that are pushed down to the lowest level possible. I eventually came to the conclusion that #ifdef's should be at a higher level (makes the code much easier to read). Perhaps it's at too high a level with version, but I want to give it a try and see how it goes.
Oct 13 2003
next sibling parent "Matthew Wilson" <matthew stlsoft.org> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bmfk7k$lkg$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bm9sds$25dr$1 digitaldaemon.com...
 No! On operating systems that do not have a drive, it is absolutely
bogus
 and evil to give them a "null" drive.

 (btw, Drive returns a char, not a string)

 Anyway, that's just the specific case. This will come up time and time
 again, probably almost as much as #define is used, so we need something
that
 works.
I know what you mean. Where I'm coming from is that I have dealt a lot
with
 code that had lots of deeply embedded #ifdef's in it that are pushed down
to
 the lowest level possible.
An enormous amount is, and for ease of porting it would be good to facilitate what is there. To have to seriously rework logic at the same time as porting is going to reduce the likely success significantly. (Which I know I don't have to tell you, but am feeling in a didactic mood, so what the hell!)
 I eventually came to the conclusion that #ifdef's
 should be at a higher level (makes the code much easier to read).
Indeed they should. However, most are not.
 Perhaps
 it's at too high a level with version, but I want to give it a try and see
 how it goes.
I've tried. We've seen. Case proven, m'lod
Oct 13 2003
prev sibling parent reply The Lone Haranguer <The_member pathlink.com> writes:
In article <bmfk7k$lkg$1 digitaldaemon.com>, Walter says...
but I want to give it a try and see
how it goes.
Ah, so D is just an experimental language, I see.
Oct 13 2003
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
I think we just wish it was an experimental language.  ;)

Sean

"The Lone Haranguer" <The_member pathlink.com> wrote in message
news:bmfnf0$pkg$1 digitaldaemon.com...
 In article <bmfk7k$lkg$1 digitaldaemon.com>, Walter says...
 but I want to give it a try and see
how it goes.
Ah, so D is just an experimental language, I see.
Oct 14 2003
prev sibling next sibling parent "Carlos Santander B." <carlos8294 msn.com> writes:
---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 2003-10-09
Oct 12 2003
prev sibling parent "Carlos Santander B." <carlos8294 msn.com> writes:
"Jan-Eric Duden" <jeduden whisset.com> wrote in message
news:bm65lf$58d$1 digitaldaemon.com...
| I guess we  need to get rid of our old "macro" habbits and rethink. :)
| Or do you have a problem where version won't work at all?
|
| --
| Jan-Eric Duden

(Sorry for that previous one)

I believe that's something that happens when we all go from one language to
another.

—————————————————————————
Carlos Santander
"Jan-Eric Duden" <jeduden whisset.com> wrote in message
news:bm65lf$58d$1 digitaldaemon.com...
| I guess we  need to get rid of our old "macro" habbits and rethink. :)
| Or do you have a problem where version won't work at all?
|
| --
| Jan-Eric Duden

(Sorry for that previous one)

I believe that's something that happens when we all go from one language to
another.

—————————————————————————
Carlos Santander
Oct 12 2003
prev sibling parent reply "Nicolas Repiquet" <deadcow-remove-this free.fr> writes:
"Matthew Wilson" <matthew stlsoft.org> a écrit dans le message news:
bm60qd$30eh$1 digitaldaemon.com...

 This does not compile. Understandably, the compiler doesn't like the brace
 indicated. What are my options? Do I have to include the body of the if
 statement twice? That doesn't help maintainability, does it?

 I think version should either use a different brace, or should use a
 different format altogether. Otherwise we'll be decreasing
maintainability,
 rather than increasing it.

 Harummpphh!
Using different brace brings us back to the awful c-like preprocessor. Versioning is part of D's syntax, and that's great. But I agree that some versioning features are missing. I'm thinking about a version(...) expression returning a constant boolean. So you can solve your problem like that : recls_assert(0 == strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck)); if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck)) { fprintf(stderr, "Path is different from path ..." ); abort(); } Constant folding optimization will (probably ?) make it as efficient as old #if syntax. -- Nicolas Repiquet
Oct 10 2003
next sibling parent reply Hauke Duden <H.NS.Duden gmx.net> writes:
Nicolas Repiquet wrote:
 Using different brace brings us back to the awful c-like preprocessor.
 Versioning is part of D's syntax, and that's great. But I agree that some
 versioning features are missing. I'm thinking about a version(...)
 expression returning a constant boolean. So you can solve your problem like
 that :
 
   recls_assert(0 == strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck));
   if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck))
   {
     fprintf(stderr, "Path is different from path ..." );
     abort();
   }
 
 
 Constant folding optimization will (probably ?) make it as efficient as old
 #if syntax.
I like that! It is still not as powerful as #ifdefs were, but it adds a lot of flexibility for situations where the difference between versions are only parametrical (i.e. same code with different values). Hauke
Oct 10 2003
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
I second this request.

version(x) { } should only be legal where a statement or declaration is
legal.

version(x) should be legal anywhere an expression is legal.

Sean

"Hauke Duden" <H.NS.Duden gmx.net> wrote in message
news:bm6l14$php$1 digitaldaemon.com...
 Nicolas Repiquet wrote:
 Using different brace brings us back to the awful c-like preprocessor.
 Versioning is part of D's syntax, and that's great. But I agree that
some
 versioning features are missing. I'm thinking about a version(...)
 expression returning a constant boolean. So you can solve your problem
like
 that :

   recls_assert(0 == strcmp(path + ( version(Windows) ? 0 : 2 ),
pathCheck));
   if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck))
   {
     fprintf(stderr, "Path is different from path ..." );
     abort();
   }


 Constant folding optimization will (probably ?) make it as efficient as
old
 #if syntax.
I like that! It is still not as powerful as #ifdefs were, but it adds a lot of flexibility for situations where the difference between versions are only parametrical (i.e. same code with different values). Hauke
Oct 10 2003
prev sibling next sibling parent "Carlos Santander B." <carlos8294 msn.com> writes:
---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 2003-10-09
Oct 12 2003
prev sibling next sibling parent "Carlos Santander B." <carlos8294 msn.com> writes:
"Nicolas Repiquet" <deadcow-remove-this free.fr> wrote in message
news:bm66gs$68l$1 digitaldaemon.com...
|
|
|   recls_assert(0 == strcmp(path + ( version(Windows) ? 0 : 2 ),
pathCheck));
|   if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck))
|   {
|     fprintf(stderr, "Path is different from path ..." );
|     abort();
|   }
|
|

(Sorry for that one too)

I also like that.

—————————————————————————
Carlos Santander


---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 2003-10-09
Oct 12 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Nicolas Repiquet" <deadcow-remove-this free.fr> wrote in message
news:bm66gs$68l$1 digitaldaemon.com...
 Using different brace brings us back to the awful c-like preprocessor.
 Versioning is part of D's syntax, and that's great. But I agree that some
 versioning features are missing. I'm thinking about a version(...)
 expression returning a constant boolean. So you can solve your problem
like
 that :

   recls_assert(0 == strcmp(path + ( version(Windows) ? 0 : 2 ),
pathCheck));
   if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck))
   {
     fprintf(stderr, "Path is different from path ..." );
     abort();
   }


 Constant folding optimization will (probably ?) make it as efficient as
old
 #if syntax.
I'm probably alone in my opinion on this <g>, but I like to see conditional compilation at a higher level than the expression level.
Oct 13 2003
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Walter wrote:
 "Nicolas Repiquet" <deadcow-remove-this free.fr> wrote in message
 news:bm66gs$68l$1 digitaldaemon.com...
  if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck))
  {
    fprintf(stderr, "Path is different from path ..." );
    abort();
  }


Constant folding optimization will (probably ?) make it as efficient as
old
#if syntax.
I'm probably alone in my opinion on this <g>, but I like to see conditional compilation at a higher level than the expression level.
Here's an idea. We could retain the version() syntax at the statement level and add a keyword called "define" maybe for the expression level. Something that I think could really hold back the power of version() is the inability to do even simple booleans (limited to version specifiers) or specify multiple versions at the same time, such as version(NORWEGIAN || SPANISH) version(NORWEGIAN, SPANISH) version(NORWEGIAN && !UNITED_STATES) etc. #define is messy, but it is *very* flexible. (Not that I know C or C++.) Justin
Oct 13 2003
parent reply "Charles Sanders" <sanders-consulting comcast.net> writes:
I really hope #define's not brought back, the main argument ive seens is
that of porting, which seems a sort of 'backward-compatility' issue.  I
understand the porting is important, but in my opionon not enough to change
the language.  I would like to see JC's || and && implemented though.

C


"J C Calvarese" <jcc7 cox.net> wrote in message
news:bmfn3r$p81$1 digitaldaemon.com...
 Walter wrote:
 "Nicolas Repiquet" <deadcow-remove-this free.fr> wrote in message
 news:bm66gs$68l$1 digitaldaemon.com...
  if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck))
  {
    fprintf(stderr, "Path is different from path ..." );
    abort();
  }


Constant folding optimization will (probably ?) make it as efficient as
old
#if syntax.
I'm probably alone in my opinion on this <g>, but I like to see
conditional
 compilation at a higher level than the expression level.
Here's an idea. We could retain the version() syntax at the statement level and add a keyword called "define" maybe for the expression level. Something that I think could really hold back the power of version() is the inability to do even simple booleans (limited to version specifiers) or specify multiple versions at the same time, such as version(NORWEGIAN || SPANISH) version(NORWEGIAN, SPANISH) version(NORWEGIAN && !UNITED_STATES) etc. #define is messy, but it is *very* flexible. (Not that I know C or C++.) Justin
Oct 13 2003
parent reply "Matthew Wilson" <matthew stlsoft.org> writes:
"Charles Sanders" <sanders-consulting comcast.net> wrote in message
news:bmfne8$pj4$1 digitaldaemon.com...
 I really hope #define's not brought back, the main argument ive seens is
 that of porting, which seems a sort of 'backward-compatility' issue.
<sarcastic:friendly> So you want D to only ever run on one version of one flavour of one platform? Shall we say Windows 2000 (NT family) on 686? </sarcastic:friendly> This issue is not just about porting from another language to D. That's just the latest thing that's given me cause to complain, i.e. when porting C++ code into the recls D mapping. But this has caused much hassle in other D code, in the registry library, and I complained about it then. To take my sarcastic comment seriously, it is quite true that if we do not provide sophisticated versioning within the language (and the current method is anything but), then we're going to have to stick to one platform, or we'll be jumping through hoops just as large (albeit less secretive) as are required in C and C++ with the preprocessor. And let me make a "stance" observation: I like the C pre-processor, and I believe it, or something like it, should be available in all languages. However, that's not to say I like macros; I don't. Macros stink, and every time I have to use/write one I am much less happy than I am with using goto. (If you look at the STLSoft libs, you'll see plenty of #if discrimination, in order to support so many compilers and platforms, but you'll see very few macros, and I've cried a little tear for each. <g>)
Oct 13 2003
parent The Lone Haranguer <The_member pathlink.com> writes:
In article <bmfpcs$s87$1 digitaldaemon.com>, Matthew Wilson says...
"Charles Sanders" <sanders-consulting comcast.net> wrote in message
news:bmfne8$pj4$1 digitaldaemon.com...
 I really hope #define's not brought back, the main argument ive seens is
 that of porting, which seems a sort of 'backward-compatility' issue.
<sarcastic:friendly> So you want D to only ever run on one version of one flavour of one platform? Shall we say Windows 2000 (NT family) on 686? </sarcastic:friendly> This issue is not just about porting from another language to D. That's just the latest thing that's given me cause to complain, i.e. when porting C++ code into the recls D mapping. But this has caused much hassle in other D code, in the registry library, and I complained about it then. To take my sarcastic comment seriously, it is quite true that if we do not provide sophisticated versioning within the language (and the current method is anything but), then we're going to have to stick to one platform, or we'll be jumping through hoops just as large (albeit less secretive) as are required in C and C++ with the preprocessor. And let me make a "stance" observation: I like the C pre-processor, and I believe it, or something like it, should be available in all languages. However, that's not to say I like macros; I don't. Macros stink, and every time I have to use/write one I am much less happy than I am with using goto. (If you look at the STLSoft libs, you'll see plenty of #if discrimination, in order to support so many compilers and platforms, but you'll see very few macros, and I've cried a little tear for each. <g>)
As has been said here before -- you can pass whatever file you want through the "C preprocessor". It is probably time to stop calling it that anyway and rename it, something like "the ANSI standard text replacement facility" (oh wait, then there can't be pragmas, oh well). As the D docs say; "the preprocessor is a different language from C".
Oct 14 2003
prev sibling parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
I have my doubts too, but there have been times in C++ where I wished I
could do it.

Sean

"Walter" <walter digitalmars.com> wrote in message
news:bmfkqg$mbk$1 digitaldaemon.com...
 "Nicolas Repiquet" <deadcow-remove-this free.fr> wrote in message
 news:bm66gs$68l$1 digitaldaemon.com...
 Using different brace brings us back to the awful c-like preprocessor.
 Versioning is part of D's syntax, and that's great. But I agree that
some
 versioning features are missing. I'm thinking about a version(...)
 expression returning a constant boolean. So you can solve your problem
like
 that :

   recls_assert(0 == strcmp(path + ( version(Windows) ? 0 : 2 ),
pathCheck));
   if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck))
   {
     fprintf(stderr, "Path is different from path ..." );
     abort();
   }


 Constant folding optimization will (probably ?) make it as efficient as
old
 #if syntax.
I'm probably alone in my opinion on this <g>, but I like to see
conditional
 compilation at a higher level than the expression level.
Oct 14 2003