Jump to page: 1 27  
Page
Thread overview
Why typedef's shouldn't have been removed :(
May 05, 2012
Mehrdad
May 05, 2012
Maxim Fomin
May 05, 2012
Mehrdad
May 05, 2012
Mehrdad
May 05, 2012
bearophile
May 05, 2012
Gor Gyolchanyan
May 05, 2012
Michel Fortin
May 05, 2012
Mehrdad
May 05, 2012
Gor Gyolchanyan
May 05, 2012
Mehrdad
May 05, 2012
Gor Gyolchanyan
May 05, 2012
Mehrdad
May 05, 2012
Gor Gyolchanyan
May 05, 2012
Mehrdad
May 05, 2012
Chris Cain
May 05, 2012
Mehrdad
May 06, 2012
Matt Peterson
May 06, 2012
Mehrdad
May 06, 2012
Matt Peterson
May 06, 2012
Mehrdad
May 06, 2012
Matt Peterson
May 06, 2012
Chris Cain
May 06, 2012
Chris Cain
May 06, 2012
Mehrdad
May 06, 2012
Chris Cain
May 07, 2012
Mehrdad
May 07, 2012
Mehrdad
May 07, 2012
Mehrdad
May 07, 2012
Mehrdad
May 08, 2012
Gor Gyolchanyan
May 09, 2012
Christophe
May 07, 2012
Francois Chabot
May 11, 2012
Mehrdad
May 11, 2012
Mehrdad
May 11, 2012
Andrej Mitrovic
May 11, 2012
Chris Cain
May 11, 2012
Robert DaSilva
May 11, 2012
Chris Cain
May 11, 2012
David Nadlinger
May 11, 2012
Timon Gehr
May 08, 2012
bearophile
May 08, 2012
mta`chrono
May 08, 2012
Jonathan M Davis
May 09, 2012
mta`chrono
May 09, 2012
Jonathan M Davis
May 09, 2012
mta`chrono
May 06, 2012
Michel Fortin
May 06, 2012
John Campbell
May 06, 2012
Andrej Mitrovic
May 07, 2012
mta`chrono
May 17, 2012
Mehrdad
May 17, 2012
Jonathan M Davis
May 17, 2012
Andrej Mitrovic
May 17, 2012
H. S. Teoh
May 17, 2012
bearophile
May 17, 2012
H. S. Teoh
May 05, 2012
Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...

this should really be fixed...
May 05, 2012
On Saturday, 5 May 2012 at 05:02:48 UTC, Mehrdad wrote:
> Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...
>
> this should really be fixed...

Features like this:

typedef int type = 5;
type var;
var.init; // is 5

AFAIK are also lost.
May 05, 2012
And for those who couldn't care less about Windows, I should also note that it's impossible to distinguish between size_t and uint, etc.

On Saturday, 5 May 2012 at 05:25:29 UTC, Maxim Fomin wrote:
> On Saturday, 5 May 2012 at 05:02:48 UTC, Mehrdad wrote:
>> Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...
>>
>> this should really be fixed...
>
> Features like this:
>
> typedef int type = 5;
> type var;
> var.init; // is 5
>
> AFAIK are also lost.
May 05, 2012
(Sorry that wasn't meant to be directed at you, I just happened
to click reply on your post)

On Saturday, 5 May 2012 at 05:25:29 UTC, Maxim Fomin wrote:
> On Saturday, 5 May 2012 at 05:02:48 UTC, Mehrdad wrote:
>> Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...
>>
>> this should really be fixed...
>
> Features like this:
>
> typedef int type = 5;
> type var;
> var.init; // is 5
>
> AFAIK are also lost.


May 05, 2012
Mehrdad:
> Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...
>
> this should really be fixed...

typedef is a quite useful feature, but the one present in D was unsound/broken, especially in presence of OOP. Fixing language features is hard (people didn't seem to understand that typedef is not meant to be used with classes), once their semantics is defined, it's quite hard to fix it. But adding features to D/Phobos is much simpler. So once there is a clear and sound design for what this feature has to do and its semantics, I expect to see in D a way to do the same things. Currently the Typedef in Phobos is more broken than the built-in typedef. Here the Ada language is a good reference to copy from. So the idea of removing typedef was good iff we eventually have something good to replace it.

Bye,
bearophile
May 05, 2012
On 2012-05-05 05:02:44 +0000, "Mehrdad" <wfunction@hotmail.com> said:

> Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...
> 
> this should really be fixed...

It should be fixed indeed. Perhaps HWND should be defined more like this:

	struct HWND { void *handle; }

Or if you want it to implement some kind of inheritance scheme:

	struct HANDLE { void *ptr; }
	struct HWND { HANDLE handle; alias handle this; }

That's still a lot better than typedef since you can control what operations are allowed on the type. For instance, you can't multiply two handles with the struct definition, with typedef you could.

My only fear is that this might not work play well with the C calling convention (or Window's in this case). If that's the case, then it's a good argument for having a separate language construct.

-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

May 05, 2012
mixin template TypeDef(Type, string name, Type init)
{
    mixin(`struct `~name~` { public alias _impl this; private Type
_impl = init; };`);
}

unittest
{
    mixin TypeDef!(int, `MyInt`, 5);

    MyInt mi;

    assert(typeid(myInt) != typeid(int));
    assert(mi == 5);
}

On Sat, May 5, 2012 at 3:09 PM, bearophile <bearophileHUGS@lycos.com> wrote:
> Mehrdad:
>
>> Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...
>>
>> this should really be fixed...
>
>
> typedef is a quite useful feature, but the one present in D was unsound/broken, especially in presence of OOP. Fixing language features is hard (people didn't seem to understand that typedef is not meant to be used with classes), once their semantics is defined, it's quite hard to fix it. But adding features to D/Phobos is much simpler. So once there is a clear and sound design for what this feature has to do and its semantics, I expect to see in D a way to do the same things. Currently the Typedef in Phobos is more broken than the built-in typedef. Here the Ada language is a good reference to copy from. So the idea of removing typedef was good iff we eventually have something good to replace it.
>
> Bye,
> bearophile



-- 
Bye,
Gor Gyolchanyan.
May 05, 2012
How do you fix it for size_t and uint, etc.?

On Saturday, 5 May 2012 at 13:01:08 UTC, Michel Fortin wrote:
> On 2012-05-05 05:02:44 +0000, "Mehrdad" <wfunction@hotmail.com> said:
>
>> Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...
>> 
>> this should really be fixed...
>
> It should be fixed indeed. Perhaps HWND should be defined more like this:
>
> 	struct HWND { void *handle; }
>
> Or if you want it to implement some kind of inheritance scheme:
>
> 	struct HANDLE { void *ptr; }
> 	struct HWND { HANDLE handle; alias handle this; }
>
> That's still a lot better than typedef since you can control what operations are allowed on the type. For instance, you can't multiply two handles with the struct definition, with typedef you could.
>
> My only fear is that this might not work play well with the C calling convention (or Window's in this case). If that's the case, then it's a good argument for having a separate language construct.


May 05, 2012
See my version.

On Sat, May 5, 2012 at 10:20 PM, Mehrdad <wfunction@hotmail.com> wrote:
> How do you fix it for size_t and uint, etc.?
>
>
> On Saturday, 5 May 2012 at 13:01:08 UTC, Michel Fortin wrote:
>>
>> On 2012-05-05 05:02:44 +0000, "Mehrdad" <wfunction@hotmail.com> said:
>>
>>> Now it's impossible to figure out whether a ParameterTypeTuple contains an HWND versus an HGDIOBJ or whatever...
>>>
>>> this should really be fixed...
>>
>>
>> It should be fixed indeed. Perhaps HWND should be defined more like this:
>>
>>        struct HWND { void *handle; }
>>
>> Or if you want it to implement some kind of inheritance scheme:
>>
>>        struct HANDLE { void *ptr; }
>>        struct HWND { HANDLE handle; alias handle this; }
>>
>> That's still a lot better than typedef since you can control what operations are allowed on the type. For instance, you can't multiply two handles with the struct definition, with typedef you could.
>>
>> My only fear is that this might not work play well with the C calling convention (or Window's in this case). If that's the case, then it's a good argument for having a separate language construct.
>
>
>



-- 
Bye,
Gor Gyolchanyan.
May 05, 2012
The one with TypeDef?

That's not how it's defined though.

On Saturday, 5 May 2012 at 18:31:44 UTC, Gor Gyolchanyan wrote:
> See my version.
« First   ‹ Prev
1 2 3 4 5 6 7