Topic: class A = B; could substitute typedef
Author: mwoolf@cix.compulink.co.uk ("Matthew Woolf")
Date: Tue, 24 Jan 1995 11:48:50 GMT Raw View
Would we still be allow type definitions like:
class char_ptr = char * ; // was: typedef char *char_ptr l
Author: ti953017@rzcipa01.rz.tu-bs.de (Andreas Rossberg)
Date: 10 Jan 1995 17:16:36 GMT Raw View
I have wondered about the following (sorry if someone did already come
up with the same idea, it's really obvious, I believe).
The namespace-alias-definition has the form
namespace A = B;
Why not introducing an equivalent syntax for `class-alias-definitions',
thereby (some day) getting rid of the obscure typedef construct in C++
programs? For example,
class A = B;
class pvfii = void (*)(int, int);
class XNode = X::Node<int, Y>;
instead of
typedef B A;
typedef void (*pvfii)(int, int);
typedef X::Node<int, Y> XNode;
Pros:
1. It is quite trivial to implement as an extension.
2. It would smooth out a common source of confusion (look at the frequent
newbie irritation involving typedef and even the erroneous answers given
by some `experts' on comp.lang.c++) because it is more readable and
intuitive.
3. It renders the syntax more symmetric because:
a) It is exactly the same syntax as used for template default arguments.
b) It is the same syntax as used for namespaces (with regard to the
current discussion about the relationship between both).
c) typedef always had a very special `out-of-style' syntax (IMHO).
Semantically analogous constructs should be syntactically analogous as
well.
Cons:
1. Two constructs for the same purpose (being forced to keep typedef not
only as an anachronism but for C compatibility).
What I suggest would therefore not be just another extension or `neat
feature', but merely a syntax cleanup (for native C++).
Syntax should not always be considered secondary. I am convinced of the
superiority of this other syntax since I read the STL sources with its long,
ugly and difficult-to-read lists of typedefs involving template argument
lists and scoping appearing in every class. Am I the only one who has a
strong dislike of the odd typedef style?
- Andreas Rossberg
Author: esap@kaarne.cs.tut.fi (Pulkkinen Esa)
Date: 10 Jan 1995 21:09:23 GMT Raw View
Andreas Rossberg (ti953017@rzcipa01.rz.tu-bs.de) wrote:
: namespace A = B;
: Why not introducing an equivalent syntax for
: `class-alias-definitions', thereby (some day) getting rid of the obscure
: typedef construct in C++ programs? For example,
: class A = B;
: class pvfii = void (*)(int, int);
: class XNode = X::Node<int, Y>;
IMHO there's no need for this. I think that preferably one should
change the namespace alias syntax to conform to the typedef syntax.
: 1. It is quite trivial to implement as an extension.
: 2. It would smooth out a common source of confusion (look at the frequent
: newbie irritation involving typedef and even the erroneous answers
: given by some `experts' on comp.lang.c++) because it is more readable
: and intuitive.
: 3. It renders the syntax more symmetric because:
: a) It is exactly the same syntax as used for template default
: arguments.
: b) It is the same syntax as used for namespaces (with regard to the
: current discussion about the relationship between both).
: c) typedef always had a very special `out-of-style' syntax (IMHO).
The same things could also be used against this proposal, for example:
1. It's more trivial to change a new construct (namespaces) than to change
something well known and widely used (typedefs).
2. You can't remove confusion with this, the same syntax is used
in declarations (well... some people don't like them either.... :)
3. a) b) typedef syntax is the same as declaration syntax.
c) That's a matter of taste, different people have different style.
: Semantically analogous constructs should be syntactically analogous as
: well.
True, but a typedef is semantically analogous to _both_ declarations and
namespace aliases. compare:
void (*my_function_pointer )(void);
typedef void (*my_function_pointer_type)(void);
void (MyClass::*PTMC )(int,int,int);
typedef void (MyClass::*PTMCT)(int,int,int);
--
Esa Pulkkinen | C++ programmers do it virtually
E-Mail: esap@cs.tut.fi | everywhere with a class, resulting
WWW : http://www.cs.tut.fi/~esap/ | in multiple inheritance.
Author: ghogenso@u.washington.edu (Gordon Hogenson)
Date: 10 Jan 1995 23:45:42 GMT Raw View
ti953017@rzcipa01.rz.tu-bs.de (Andreas Rossberg) writes:
> I have wondered about the following (sorry if someone did already come
>up with the same idea, it's really obvious, I believe).
> The namespace-alias-definition has the form
> namespace A = B;
> Why not introducing an equivalent syntax for `class-alias-definitions',
>thereby (some day) getting rid of the obscure typedef construct in C++
>programs? For example,
> class A = B;
> class pvfii = void (*)(int, int);
> class XNode = X::Node<int, Y>;
>instead of
> typedef B A;
> typedef void (*pvfii)(int, int);
> typedef X::Node<int, Y> XNode;
I like your suggestion. In my mind, namespace behavior should be inherited
by classes, so adding this as an extension solidifies the "is-a"
relationship between a class and a namespace (which is a Good Thing).
IMNO, namespaces are a very modern, elegant concept, which is crippled by
having been adopted in a very limited form, touted as a solution to
one small problem. Namespace-like behavior should be inherited by classes
unless there is a good reason not to.
> Syntax should not always be considered secondary. I am convinced of the
>superiority of this other syntax since I read the STL sources with its long,
>ugly and difficult-to-read lists of typedefs involving template argument
>lists and scoping appearing in every class. Am I the only one who has a
>strong dislike of the odd typedef style?
No. Although I'm used to it by now, I often explain it to people.
The confusion arises because typedef syntax is analogous to declarator
syntax. This is spurious because the two concepts are totally unrelated.
The namespace alias concept is much closer to what a typedef does than
a declarator.
> - Andreas Rossberg
Gordon.
Author: ti953017@rzcipa01.rz.tu-bs.de (Andreas Rossberg)
Date: 11 Jan 1995 16:19:59 GMT Raw View
In article <3eut23$8h5@peippo.cs.tut.fi>,
Pulkkinen Esa <esap@kaarne.cs.tut.fi> wrote:
>
> Andreas Rossberg (ti953017@rzcipa01.rz.tu-bs.de) wrote:
> : namespace A = B;
> :
> : Why not introducing an equivalent syntax for
> : `class-alias-definitions', thereby (some day) getting rid of the obscure
> : typedef construct in C++ programs? For example,
> :
> : class A = B;
> : class pvfii = void (*)(int, int);
> : class XNode = X::Node<int, Y>;
>
> IMHO there's no need for this. I think that preferably one should
> change the namespace alias syntax to conform to the typedef syntax.
Hope that does not happen :-)
> [...]
> 1. It's more trivial to change a new construct (namespaces) than to change
> something well known and widely used (typedefs).
> 2. You can't remove confusion with this, the same syntax is used
> in declarations (well... some people don't like them either.... :)
> 3. a) b) typedef syntax is the same as declaration syntax.
> c) That's a matter of taste, different people have different style.
>
> : Semantically analogous constructs should be syntactically analogous as
> : well.
>
> True, but a typedef is semantically analogous to _both_ declarations and
> namespace aliases.
No, a typedef is _syntactically_ analogous to object declarations but
_semantically_ analogous to namespace aliases. That's why it's confusing.
As in
article <3ev676$kj3@nntp1.u.washington.edu>,
Gordon Hogenson <ghogenso@u.washington.edu> wrote:
>
> The confusion arises because typedef syntax is analogous to declarator
> syntax. This is spurious because the two concepts are totally unrelated.
> The namespace alias concept is much closer to what a typedef does than
> a declarator.
And even without the existance of namespaces the class A = B syntax would
be preferable IMHO, simply because it's also much closer to the class
declaration syntax.
But of course, the most important argument is readability.
- Andreas Rossberg