digitalmars.D - Re: typedef: what's it good for?
- Justin Johansson <no spam.com> Nov 11 2009
rmcguire Wrote:Justin Johansson <no spam.com> wrote:Walter Bright Wrote:When I originally worked out ideas for D, there were many requests from the C and C++ community for a 'strong' typedef, and so I put one in D. I didn't think about it too much, just assumed that it was a good idea. Now I'm not so sure. Maybe it should be removed for D2. Does anyone use typedef's? What do you use them for? Do you need them?
Early on (2 months ago) when I was just getting into D I asked about typedefs
and some discussion transpired. http://www.digitalmars.com/d/archives/digitalmars/D/
(btw. There are a few responses from blasts from recent pasts in that thread.) Anyway, grepping for typedef over my current "scripting-language in D" project
shows only old versions of my project using typedefs. Accordingly it looks
since managed to convert *all* of my previous typedef incarnations to structs
take advantage of struct's support for static opCall so as to synthesize
(as well enabling use of struct methods). Maybe I didn't know enough about D back then, but the big problem with D
(for me at least) was there was no support for typedef constructors and code
blotted with cast-to-typedef-type is yuk in my way of thinking. I think there are only two sensible courses of action for D: support typedef
(and methods???) or remove 'em. I'm not sure which option I prefer (is the
an option?) Cheers Justin Johansson
I like typedef for making header files for c libraries. For example, so that you can't just pass an int to a function expecting an id.
Yep; I agree that's a good use for typedefs too .. but in the current D formulation, you still need to use a cast don't you?
Nov 11 2009