public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Re: c++ "with" keyword
@ 2002-12-29  8:32 Norman Jonas
  2002-12-29 12:46 ` Russ Allbery
  0 siblings, 1 reply; 5+ messages in thread
From: Norman Jonas @ 2002-12-29  8:32 UTC (permalink / raw)
  To: gcc

I think you missed the point. The reason for the with keyword is not to use
a pointer but to leave
the long structs name which is not done by your example :

struct S
{
    char* name;
    char* street;
    char* city;
} verylongdescriptivename;

If you want to access several values of this struct you always have to type
in the whole name :

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

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* )

Norman

> erik wrote :
>
> The example
>
>  struct S
>  {
>      int x;
>      int y;
>  };
>
>  int main()
>  {
>      S s;
>      with (s)
>      {
>          .x = 1;
>          .y = 2;
>      }
>      return 0;
>  }
>
> can easily be rewritten by introducing temporary references, as in
>
>  int main()
>  {
>      S s;
>      {
>          S& t = s;
>          t.x = 1;
>          t.y = 2;
>      }
>      return 0;
>  }
>
> This requires only one additional variable reference each time the
> "with" object is used.  Additionally, it allows several "with" objects
> (with different names) at the same time.  In C, the same thing can be
> done by using pointers.
>
> -erik

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: c++ "with" keyword
  2002-12-29  8:32 Re: c++ "with" keyword Norman Jonas
@ 2002-12-29 12:46 ` Russ Allbery
  0 siblings, 0 replies; 5+ messages in thread
From: Russ Allbery @ 2002-12-29 12:46 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: c++ "with" keyword
@ 2003-01-18  7:53 Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 2003-01-18  7:53 UTC (permalink / raw)
  To: dewar, fjh; +Cc: gcc, normanjonas

> My viewpoint is slightly different: GCC *should* be used as an arena for
> implementing random language extensions, but in general those extensions
> should not be merged into the main CVS branch.  (They would only be merged
> on the main branch if there is a *very* convincing case made for them.)

Yes, of course it is fine to use GCC as an arena for playing with language
extensions. I did not mean to imply otherwise. I was talking about the
official release.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: c++ "with" keyword
  2003-01-04 14:29 Robert Dewar
@ 2003-01-14 14:33 ` Fergus Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Fergus Henderson @ 2003-01-14 14:33 UTC (permalink / raw)
  To: Robert Dewar; +Cc: gcc, normanjonas

On 04-Jan-2003, Robert Dewar <dewar@gnat.com> wrote:
> > I think you missed the point. The reason for the with keyword is not to use
> > a pointer but to leave
> > the long structs name which is not done by your example :
> 
> My viewpoint here is that gcc should not be used as an arena for
> implementing random language extensions, no matter how meritorious
> they be.

My viewpoint is slightly different: GCC *should* be used as an arena for
implementing random language extensions, but in general those extensions
should not be merged into the main CVS branch.  (They would only be merged
on the main branch if there is a *very* convincing case made for them.)

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: c++ "with" keyword
@ 2003-01-04 14:29 Robert Dewar
  2003-01-14 14:33 ` Fergus Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Dewar @ 2003-01-04 14:29 UTC (permalink / raw)
  To: gcc, normanjonas

> I think you missed the point. The reason for the with keyword is not to use
> a pointer but to leave
> the long structs name which is not done by your example :

My viewpoint here is that gcc should not be used as an arena for
implementing random language extensions, no matter how meritorious
they be. Yes, we have some useful extensions in C that should
certainly be maintained at this stage (e.g. nested procedures),
but it is a mistake to go implementing new ones unless there is
some very convincing argument, and a simple "gosh, this woul dbe
convenient to have" is never convincing enough in this context.

If you think "with" is valuable, then the task is to convince the
guardians of the C++ standard of this. If you can't convince the
C++ community to add the feature, then I think it is a mistake
for gcc to second guess.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-01-18  0:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-29  8:32 Re: c++ "with" keyword Norman Jonas
2002-12-29 12:46 ` Russ Allbery
2003-01-04 14:29 Robert Dewar
2003-01-14 14:33 ` Fergus Henderson
2003-01-18  7:53 Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).