K
Kaz Kylheku
If "struct" is long and ugly, how about "typedef"?
The typedef is in one place; the "struct foo" is repeated in all declarations
involving that type.
If "struct" is long and ugly, how about "typedef"?
The typedef is in one place; the "struct foo" is repeated in all declarations
involving that type.
Exactly. And if "all" is a small number, using a typedef to avoid
clutter can be counterprodutive.
If "struct" is long and ugly, how about "typedef"?
What's more, in C++ you don't have to scatter "typedef" keywords about
the place either ;-)
(e-mail address removed) writes:
[responding selectively, mostly without the usual 'snip' indicators]
but that's not the only reason that people typedef structs. I do it
becasue I think the syntax is poor. I hide other hard-to-read
declaration syntax behind typedefs for the same reason. I don't do it
because I got confused about opaque types.
So I don't think they have "learned the wrong lesson"
The lesson I was talking about is "don't use typedefs". I
think you and I are in agreement that this is not the
right lesson.
ok
[confusion about naming between tags and typedef names]
To my way of thinking the main reason to use typedef names
is to encourage use of information hiding and viewing of
various entities as abstract data types.
[...]
I agree that that's the main *appropriate* reason to use typedefs for
structs. Unfortunately, it's not the main reason programmers actually
use them.
But that's a reason to talk about information hiding, ADT's, and
opaque types /more/, not to insist more strenuously that typedefs
shouldn't be used. If you show examples of where it's good to
typedef a struct, that will both strengthen an understanding of
information hiding and ADT's, etc, and also make comments about
when /not/ to use typedefs more effective.
always supposing the heavy typedefers actually /are/ confused
I think you and I are pretty close on this issue actually, but
let me restate my comment from another perspective. What are
some examples where using typedef's makes sense,
examples where using typedef's does not make sense? I believe
giving both kinds of examples will produce a better result.
(e-mail address removed) writes:
[responding selectively, mostly without the usual 'snip' indicators]
but that's not the only reason that people typedef structs. I do it
becasue I think the syntax is poor. I hide other hard-to-read
declaration syntax behind typedefs for the same reason. I don't do it
because I got confused about opaque types.
So I don't think they have "learned the wrong lesson"
The lesson I was talking about is "don't use typedefs". I
think you and I are in agreement that this is not the
right lesson.
[confusion about naming between tags and typedef names]
To my way of thinking the main reason to use typedef names
is to encourage use of information hiding and viewing of
various entities as abstract data types.
[...]
I agree that that's the main *appropriate* reason to use typedefs for
structs. Unfortunately, it's not the main reason programmers actually
use them.
But that's a reason to talk about information hiding, ADT's, and
opaque types /more/, not to insist more strenuously that typedefs
shouldn't be used. If you show examples of where it's good to
typedef a struct, that will both strengthen an understanding of
information hiding and ADT's, etc, and also make comments about
when /not/ to use typedefs more effective.
always supposing the heavy typedefers actually /are/ confused
I think you and I are pretty close on this issue actually, but
let me restate my comment from another perspective. What are
some examples where using typedef's makes sense, and some other
examples where using typedef's does not make sense? I believe
giving both kinds of examples will produce a better result.
(e-mail address removed) writes:
[responding selectively, mostly without the usual 'snip' indicators]
but that's not the only reason that people typedef structs. I do it
becasue I think the syntax is poor. I hide other hard-to-read
declaration syntax behind typedefs for the same reason. I don't do it
because I got confused about opaque types.
So I don't think they have "learned the wrong lesson"
The lesson I was talking about is "don't use typedefs". I
think you and I are in agreement that this is not the
right lesson.
[confusion about naming between tags and typedef names]
To my way of thinking the main reason to use typedef names
is to encourage use of information hiding and viewing of
various entities as abstract data types.
[...]
I agree that that's the main *appropriate* reason to use typedefs for
structs. Unfortunately, it's not the main reason programmers actually
use them.
But that's a reason to talk about information hiding, ADT's, and
opaque types /more/, not to insist more strenuously that typedefs
shouldn't be used. If you show examples of where it's good to
typedef a struct, that will both strengthen an understanding of
information hiding and ADT's, etc, and also make comments about
when /not/ to use typedefs more effective.
always supposing the heavy typedefers actually /are/ confused
I think you and I are pretty close on this issue actually, but
let me restate my comment from another perspective. What are
some examples where using typedef's makes sense, and some other
examples where using typedef's does not make sense? I believe
giving both kinds of examples will produce a better result.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.