This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: c++ "with" keyword
Tolga Dalman wrote:
On Sat, 04 Jan 2003 09:31:50 -0800 Gianni Mariani <gmariani@chaincast.com> wrote:
Andrew Haley wrote:
Momchil Velikov writes:
"Robert" == Robert Dewar <dewar@gnat.com> writes:
Robert> If you think "with" is valuable, then the task is to
Robert> convince the guardians of the C++ standard of this. If
Robert> you can't convince the
Not related to this particular "with" discussion, but I couldn't
disagree more. A standards body should not invent language
"features", but rather codify existing (proven) extensions.
I totally agree. A standards should not invent language features, or
-- heaven forbid -- programming languages. The reason for this is
pretty obvious, in that once a feature is standardized it's too late
to remove it if it has some fatal flaw.
I agree as well.
Proposals of language extensions should come from anyone :) The metrits
discussed in community and accepted as a standard once it is generally
accepted.
So, I'd like to steer the discussion back to the merits of "with".
The "with" syntax was a pain in the rear in Pascal and I never want to
see it again - this is why:
Take 2 structures, A and B which are both used in a "with" statement.
e.g. (I'll use the proposed new "with" syntax in c++ below)
Let's start with some valid working code ...
struct A {
int X;
int Y;
int hUgH;
};
struct B {
int Z;
};
int func()
{
....
A & a;
B & b;
....
with ( a )
witb ( b )
{
Y = Z;
hUgH = X; // woz this then eh ? <-- point of confusion
}
...
}
And a little later someone comes and fixes a bug and adds
struct B {
int Z;
int X; // need an X to fix The Bug (tm)
};
Oops - which X is now instantiated at "point of confusion" ?
Someone innocently added a new member and completly changed the
behaviour of the code. For code maintainability, I'd suggest that this
would cause more difficult to discover problems than would be merited.
it should be possible to disallow a "with" keyword within another "with" block.
Rendering it even more useless.
I dislike "with" in any language because it adds much more burden to
maintainers of the code. In the middle of a hundred line section of code
using with
with (some_very_long_name) with(another_very_long_name)
{
... Many lines of code
x = y; // suspect line
...Many more lines of code
}
You see a simple line of code. Now, where does 'x' come from? How
about 'y'? Is it refering to something in the structire or a global
variable? If there is both a simple variable 'x' in scope, as well as
a structure memebr 'x', which one gets used? What if 'x' exists in
both structures?
It requires the maintainer, who may not have been the original
author, to deal with much more context than if it were simply
written
x = some_very_long_name.y;
When classes are thrown into the mix, you also have the fun of
needing to trace through all the inherited classes where it may
possibly be a member. Not my idea of fun.
And to search for references to a structure becomes much more
complex. Instead of looking for a '.x' or '->x', you must now search
for 'x', and then look to see if the reference is within a 'using'
clause.
Sorry, I don't see how 'using' would improve the language in
more ways than it would harm it. Never liked it in Pascal, and
wouldn't like it in C++ either.
This is also one of the reasons I don't like namespaces much either -
hence I allways prefix identifiers that are not within a class's scope.
hm, i know a lot of people who don't like namespaces aswell, but the point is:
it'd be great to have a compiler-feature to make code more readable.
i think, long struct-names are very annoying and a common solution
If long names are causing you typing problems, then DON'T CREATE LONG
NAMES IN THE FIRST PLACE. The "standard" C and C++ libraries usually
use fairly short names for everything. Most of the long names I've seen are
those created specifically for the program in question. If the long
names are
a real problem for you, then why create them in the first place?
(either standard or compiler-addon) for this problem would be very good.
just my opinion.
If you were to implement (heaven forbid) the "with" mechanism, I'd
suggest you use the "using" keyword instead.
the actual name doesn't matter i think, but "with" is already used in other programming languages. so, why to use "using"?