Why typedef's shouldn't have been removed :(

Mehrdad wfunction at hotmail.com
Mon May 7 12:48:22 PDT 2012


On Monday, 7 May 2012 at 19:29:26 UTC, Steven Schveighoffer wrote:
> I think it was more that the whole concept was flawed -- 
> typedef int myint never really did exactly what you wanted it 
> to.
>
> For example:
>
> myint m = 1; // ok
> m += 5; // ok
> m = m + 5; // error?

It's definitely an error, because 5 isn't myint.
Of course, it wouldn't be an error in C code, but keeping source 
compatibility isn't a goal either.

Wouldn't a global search-and-replace that replaced "typedef" with 
"alias" when porting C code have fixed 99% of this issue, 
practically speaking?

> Things got even worse when you weren't typedef'ing a basic type.

It sounds so trivial to fix though (especially since it's not 
silent breakage)...
Would you mind giving another (actual) example (perhaps with a 
custom type?) that came up, and which shows the extent of the 
problem and why it was difficult to solve without disallowing 
typedef entirely?
I'm having a hard time seeing why the problem was so difficult 
(or tedious) to fix... a search/replace for typedef/alias 
would've fixed all (or almost) all the cases when porting C code, 
right?

> I think the advents in type construction in D2 have made 
> typedef almost completely implementable as a library type, and 
> we can do it the way it was intended!  Don't forget, typedef 
> was there when we had no "alias this" and no blanket operator 
> overloading.

Well, I'll have to try it and see -- I neither agree nor disagree.
Right now I'm just trying to understand the problems it was 
causing, though.

> When all you want is an opaque type that just can't be 
> implicitly cast from something else (such as HANDLE) typedef is 
> a crude and inaccurate method to do that.

I don't really agree with that (though an example as I asked for 
above^ could definitely make me agree)

> Maybe it wasn't you, let me check...
>
> http://forum.dlang.org/post/jnueti$1opd$1@digitalmars.com
>
> OK, it was you, but under a different context, and I actually 
> don't see you mentioning C there.  Sorry for the 
> confusion/accusation.  I have a hard time keeping track of all 
> these different threads in my head :(

Haha no worries. :)

> Seriously though, I get what you are saying. [...] The chances 
> of your pull request being validated and pulled -- if it makes 
> a good improvement to phobos -- are much much higher than they 
> used to be.

Awesome, I'll probably try my hand at it (probably around next 
week). :)


More information about the Digitalmars-d mailing list