Topic: C++ naming ... a wide subject
Author: verec@mac.com (verec)
Date: Mon, 27 Jun 2005 22:50:11 GMT Raw View
So, somehwere in the mid 90's, C++ introduced a host of new features
and hence, associated keywords.
- We'd like to be able to manipulate types. So types must have some
kind of IDentification.
- So what about: typeId?
- Nope, that's too "Java"-esque.
- So let's agree on type_id then...
- tss! tss! typeid it is, and it should be!
- Oh wait, to play with templates and refer to builtin types
we need to be able to say something other than template <class X>
because, then, how could we deal with, e.g, 'int's?
- Yes, we want to refer to the name of type, what about typeName?
- Nope, that's too "Java"-esque.
- So let's agree on type_name then...
- tss! tss! typename it is, and it should be!
- Aha! But (this cast) is too ugly and overloaded. We need to
distinguish the various use cases: static, dynamic, const and
reinterpret.
- Oh! I get it this time! It's not going to be either of
dynamicCast or dynamic_cast (you just popooed my earlier
suggestions along those lines) so dynamiccast, staticcast,
constcast and reinterpretcast it will be! I'm so glad I got
it right this time!
- tss! tss! dynanic_cast, static_cast, reinterpret_cast and
const_cast it is, and id should be!
It might be interesting to note that, when confronted to a
problem similar to C++ dynamic_cast naming, eg:
if (Foo * f = dynanic_cast<Foo *)(x)) {
// f is a Foo * or derives from Foo
} else {
std::cout << "Not a Foo!" << std::endl ;
}
Java's James Gosling came up with
if (f instanceof Foo) {
}
Not ``instance_of'', nor ``instanceOf'', probaly because, even
though a bit weird at first, it meshed nicely with the _rest of
the language_
.
But who needs naming consistency, after all? Poets and dreamers,
certainly, not computer programmers! They've got a real product
to deliver...
It will no doubt take decades to sink in, that when one plays
with language, one plays with ideas, forms and relations,
irrespective of the proof (the program runs). Mathematicians
have been on this road for centuries, and still are, even if
"theorem proving code" is starting to appear, because you see,
_proving_ the code is the easy part ... coming up with the idea
first, _is_ the hard part. Where we need most imagination and
less impediments, inconsitencies being a major one...
My 2p :)
--
JFB
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dsp@bdal.de (=?ISO-8859-1?Q?Daniel_Kr=FCgler?=)
Date: Tue, 28 Jun 2005 13:59:41 GMT Raw View
Hello JFB,
verec wrote:
> So, somehwere in the mid 90's, C++ introduced a host of new features
> and hence, associated keywords.
>=20
[Snipping stuff unrelated to C++]
> It might be interesting to note that, when confronted to a
> problem similar to C++ dynamic_cast naming, eg:
>=20
> if (Foo * f =3D dynanic_cast<Foo *)(x)) {
> // f is a Foo * or derives from Foo
> } else {
> std::cout << "Not a Foo!" << std::endl ;
> }
>=20
> Java's James Gosling came up with
>=20
> if (f instanceof Foo) {
> }
The Java example is incomplete. The minimal necessary comparable
code would be something like:
if (x instanceof Foo) {
Foo f =3D (Foo) x;
} else {
System.out.println("Not a Foo!");
}
So what is the main difference? The main difference I see is, that
using C++ I have the opportunity to perform a single dynamic cast
attempt where on success I can immediately use the obtained object.
I always wondered, how Java could live with the essential
double-casting idiom
if (x instanceof Foo) {
Foo f =3D (Foo) x;
}
Greetings from Bremen,
Daniel Kr=FCgler
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Zara" <yozara@terra.es>
Date: Tue, 28 Jun 2005 09:03:17 CST Raw View
Oh yes! In the sake of consistency, I demand to throw all C-inherited
stuff out of C++ right now!
Seriously, inconsistency comes form having lots of people working with,
and to improve, the language. Exactly the same happend with natural
languages, they are all full of inconsistencies, irregular forms... I
suppose this means they are alive!
And I defend some of the decisisons taken: certain operations
(specially casts) should be ugly to remember us that the operation
implied is ugly by itself.
Best regards,
Zara
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: SeeWebsiteForEmail@moderncppdesign.com ("Andrei Alexandrescu (See Website For Email)")
Date: Tue, 28 Jun 2005 20:24:49 GMT Raw View
Daniel Kr=FCgler wrote:
> I always wondered, how Java could live with the essential
> double-casting idiom
>=20
> if (x instanceof Foo) {
> Foo f =3D (Foo) x;
> }
It is an inconvenience to the programmer; for the record, that's a=20
low-hanging fruit for the simplest optimizers.
Andrei
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kanze@gabi-soft.fr
Date: Wed, 29 Jun 2005 09:54:40 CST Raw View
"Andrei Alexandrescu See Website For Email wrote:
> Daniel Kr gler wrote:
> > I always wondered, how Java could live with the essential
> > double-casting idiom
> > if (x instanceof Foo) {
> > Foo f = (Foo) x;
> > }
> It is an inconvenience to the programmer; for the record,
> that's a low-hanging fruit for the simplest optimizers.
I don't think Daniel's point concerned runtime. It's a
potential source of errors -- I have to repeat the name of the
class three times in order to say I want to use it. And an
error in the first instance won't even cause a compile time
error.
Note that certain people consider the fact that I have to repete
the name of the type twice in C++ is a weakness, and propose
typeof or something like that as an improvement.
(And of course, the original problem can be solved with only
repeating the name twice in Java:
try {
Foo f = (Foo) x ;
// ...
} catch ( ClassCastException error ) {
System.out.print( "..." ) ;
}
I don't like it; if forces you to put the short, exceptional
case at the end, whereas I prefer to keep the shorter branch
near the top. Not to mention that "exception" says something
that I may not mean here.)
--
James Kanze GABI Software
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S mard, 78210 St.-Cyr-l' cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: yozara@terra.es (Juan Antonio Zaratiegui Vallecillo)
Date: Wed, 29 Jun 2005 14:54:23 GMT Raw View
OK, nothing to comment on the MVC++ solution, I know in Borland the cost
is higher, so It seems to depend on the compiler.
>My MSN search for "Stroustrup ugly cast" returned a bunch of links but none
>of them stated that a dynamic cast is ugly. NB the original paper
>WG21/N0349 did not describe the dynamic cast at all, it only mentioned it.
>
>
>
It is not exactly "ugly" the adjective, but:
" The long names and the template-like syntax of the new casts put off
some people. That may be all for the better because one of the purposes
of the new casts is to remind people that casting is a hazardous
business and to emphasize that there are different kinds of danger
involved in the use of the different operators." Bjarne Stroustrup, The
design and evolution of C++, 1994
So that's the point.
Best regards,
J.A. Zaratieuig
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]