Jump to page: 1 2 3
Thread overview
Bring back #define
Oct 10, 2003
Matthew Wilson
Oct 10, 2003
Daniel Yokomiso
Oct 10, 2003
Matthew Wilson
Oct 10, 2003
Jan-Eric Duden
Oct 10, 2003
Lars Ivar Igesund
Oct 10, 2003
Walter
Oct 11, 2003
Walter
Oct 11, 2003
Lars Ivar Igesund
Oct 12, 2003
shinichiro.h
Oct 11, 2003
Matthew Wilson
Oct 11, 2003
Walter
Oct 11, 2003
Matthew Wilson
Oct 14, 2003
Walter
Oct 14, 2003
Matthew Wilson
Oct 14, 2003
The Lone Haranguer
Oct 14, 2003
Sean L. Palmer
Oct 10, 2003
Nicolas Repiquet
Oct 10, 2003
Hauke Duden
Oct 10, 2003
Sean L. Palmer
Oct 14, 2003
Walter
Oct 14, 2003
J C Calvarese
Oct 14, 2003
Charles Sanders
Oct 14, 2003
Matthew Wilson
Oct 14, 2003
The Lone Haranguer
Oct 14, 2003
Sean L. Palmer
October 10, 2003
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!



October 10, 2003
"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


October 10, 2003
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
>
>


October 10, 2003
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
> >
> >
>
>


October 10, 2003
"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


October 10, 2003
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

October 10, 2003
"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


October 10, 2003
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


October 10, 2003
"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.


October 11, 2003
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
> > >
> > >
> >
> >
>
>


« First   ‹ Prev
1 2 3