This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++ "with" keyword


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";
    }

and

    {
        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/>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]