c++ "with" keyword

Russ Allbery rra@stanford.edu
Sun Dec 29 12:46:00 GMT 2002

Norman Jonas <normanjonas@arcor.de> writes:

> using the "with" keyword this code becomes much smaller and cleaner :

> with ( verylongdescriptivename )
> {
>     .name = "hans";
>     .street = "xxx 13";
>     .city = "cologne";
> }

> ( It is possible to use a pointer with a very short, undescriptive name,
> but that makes the code unreadable and stupid ( variables should have
> explanative names, not a confusing x* )

I must admit that I don't see the effective difference between:

    with (verylongdescriptivename)
        .name = "hans";
        .street = "xxx 13";
        .city = "cologne";


        struct S& s = verylongdescriptivename;
        s.name = "hans";
        s.street = "xxx 13";
        s.city = "cologne";

You say that variables should have long, explanative names, but the
function of with is essentially to remove those names and rely on implicit
context.  That's exactly what using short variable names does.

with is one of those constructs that renders code extremely difficult to
understand if used for blocks of code longer than a few lines, because it
complicates the way symbol lookups are performed (something that's already
incredibly complex in C++).

Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

More information about the Gcc mailing list