Re: Ensuring template argument is descendant of class

2013-12-13 Thread Brian Rogoff

On Friday, 13 December 2013 at 05:55:09 UTC, H. S. Teoh wrote:

On Fri, Dec 13, 2013 at 06:42:26AM +0100, Brian Rogoff wrote:
I'm sympathetic to this POV, or something similar. For 
example, a

multiyear plan to deprecate the 'is' syntax and replace it with
something better, in the current D. I'm not a fan of gratuitous
changes which make the language unstable, but if there were a
pleasing design to replace 'is' I'd like to think that D users 
could
change the relevant sources given a long enough deprecation 
window.


I vote for this. Good luck convincing Walter, though.


Step 1 is to come up with a set of better design alternatives,
and a transition plan, etc. I'm pretty sure I've read posts from
Walter on this forum that agree with the current 'is' is far from
ideal, so maybe convincing him is not as hard as you think,
though I imagine he has bigger fish to fry these days. Still, it
would be encouraging if the D community could address the general
issue of *not* being forced to keep bad designs forever.

-- Brian


Re: Ensuring template argument is descendant of class

2013-12-12 Thread Adam D. Ruppe

On Thursday, 12 December 2013 at 21:51:14 UTC, Ross Hays wrote:

if (cast(Asset)T)


Try this instead:

   if(is(T : Asset))

the is thing checks types. You can do is(T == Asset) for the 
specific class, or is(T : Asset) which means it implicitly 
converts to it - in otherworts, if T is Asset or a child of Asset.


Re: Ensuring template argument is descendant of class

2013-12-12 Thread Ross Hays
On Thursday, 12 December 2013 at 21:53:20 UTC, Adam D. Ruppe 
wrote:

On Thursday, 12 December 2013 at 21:51:14 UTC, Ross Hays wrote:

   if (cast(Asset)T)


Try this instead:

   if(is(T : Asset))

the is thing checks types. You can do is(T == Asset) for the 
specific class, or is(T : Asset) which means it implicitly 
converts to it - in otherworts, if T is Asset or a child of 
Asset.


Okay thank you, that seems to clear up the error. I found 
http://dlang.org/expression.html#IsExpression and had no idea is 
could be used with that syntax. The more D I learn the more 
counter-intuitive I find some aspects of the language syntax. A 
shame, that was my main point to start using it. Oh well! Thanks


Re: Ensuring template argument is descendant of class

2013-12-12 Thread Adam D. Ruppe

On Thursday, 12 December 2013 at 22:05:17 UTC, Ross Hays wrote:
http://dlang.org/expression.html#IsExpression and had no idea 
is could be used with that syntax. The more D I learn the more 
counter-intuitive I find some aspects of the language syntax.


Yeah, the is expression is one of the strangest things in D. 
Especially if you use it to deconstruct arrays and templates! But 
between the two simpler forms of is(A == B) and is(A : B), and 
http://dlang.org/phobos/std_traits.html you can get a lot done 
and it isn't so bad looking.


Re: Ensuring template argument is descendant of class

2013-12-12 Thread H. S. Teoh
On Thu, Dec 12, 2013 at 11:23:15PM +0100, Adam D. Ruppe wrote:
 On Thursday, 12 December 2013 at 22:05:17 UTC, Ross Hays wrote:
 http://dlang.org/expression.html#IsExpression and had no idea is
 could be used with that syntax. The more D I learn the more
 counter-intuitive I find some aspects of the language syntax.
 
 Yeah, the is expression is one of the strangest things in D.
 Especially if you use it to deconstruct arrays and templates! But
 between the two simpler forms of is(A == B) and is(A : B), and
 http://dlang.org/phobos/std_traits.html you can get a lot done and
 it isn't so bad looking.

Yeah, is-expression syntax is one of the dark, ugly corners of D that
unfortunately we're stuck with, because changing it now will totally
break a LOT of code for merely cosmetic reasons. I honestly wish that
one day this mess could be cleared up, though I'm not holding my breath
for it.


T

-- 
Computer Science is no more about computers than astronomy is about
telescopes. -- E.W. Dijkstra


Re: Ensuring template argument is descendant of class

2013-12-12 Thread Ross Hays
Yeah, is-expression syntax is one of the dark, ugly corners of 
D that
unfortunately we're stuck with, because changing it now will 
totally
break a LOT of code for merely cosmetic reasons. I honestly 
wish that
one day this mess could be cleared up, though I'm not holding 
my breath

for it.


T


I know this is probably obvious, but if D were allowed to just 
make one big breaking change for D3 or something, and fix every 
dark corner it has. Would that really be so bad? I know it would 
break things but... I kind of long for it.


Re: Ensuring template argument is descendant of class

2013-12-12 Thread Brian Rogoff

On Friday, 13 December 2013 at 05:22:26 UTC, Ross Hays wrote:
Yeah, is-expression syntax is one of the dark, ugly corners of 
D that
unfortunately we're stuck with, because changing it now will 
totally
break a LOT of code for merely cosmetic reasons. I honestly 
wish that
one day this mess could be cleared up, though I'm not holding 
my breath

for it.


T


I know this is probably obvious, but if D were allowed to just 
make one big breaking change for D3 or something, and fix every 
dark corner it has. Would that really be so bad? I know it 
would break things but... I kind of long for it.


I'm sympathetic to this POV, or something similar. For example, a 
multiyear plan to deprecate the 'is' syntax and replace it with 
something better, in the current D. I'm not a fan of gratuitous 
changes which make the language unstable, but if there were a 
pleasing design to replace 'is' I'd like to think that D users 
could change the relevant sources given a long enough deprecation 
window.


Changing every dark corner and every poor choice is too much. For 
instance, a lot of people think that immutability and 'nothrow' 
should have been the default, but changing that would be dramatic 
and probably will have to wait for a D3 or new language.


-- Brian


Re: Ensuring template argument is descendant of class

2013-12-12 Thread H. S. Teoh
On Fri, Dec 13, 2013 at 06:42:26AM +0100, Brian Rogoff wrote:
 On Friday, 13 December 2013 at 05:22:26 UTC, Ross Hays wrote:
 Yeah, is-expression syntax is one of the dark, ugly corners of D
 that unfortunately we're stuck with, because changing it now will
 totally break a LOT of code for merely cosmetic reasons. I honestly
 wish that one day this mess could be cleared up, though I'm not
 holding my breath for it.
 
 
 T
 
 I know this is probably obvious, but if D were allowed to just
 make one big breaking change for D3 or something, and fix every
 dark corner it has. Would that really be so bad? I know it would
 break things but... I kind of long for it.
 
 I'm sympathetic to this POV, or something similar. For example, a
 multiyear plan to deprecate the 'is' syntax and replace it with
 something better, in the current D. I'm not a fan of gratuitous
 changes which make the language unstable, but if there were a
 pleasing design to replace 'is' I'd like to think that D users could
 change the relevant sources given a long enough deprecation window.

I vote for this. Good luck convincing Walter, though.


 Changing every dark corner and every poor choice is too much. For
 instance, a lot of people think that immutability and 'nothrow'
 should have been the default, but changing that would be dramatic
 and probably will have to wait for a D3 or new language.
[...]

Not to mention such a big change (or such numerous fundamental changes)
would probably introduce new dark corners that then need fixing. :)
Language design ain't easy.


T

-- 
It is of the new things that men tire --- of fashions and proposals and
improvements and change. It is the old things that startle and
intoxicate. It is the old things that are young. -- G.K. Chesterton


Re: Ensuring template argument is descendant of class

2013-12-12 Thread Ross Hays
I remember seeing some posts about D and how the way it sounded 
was that D kind of filled the role of C++, without all the burden 
of years of full backwards comparability. I wouldn't dare say it 
is that bad, but this is how the problem starts I feel. I would 
love to see a release cycle like you mentioned. Something like 
OpenGL deprecating would be great but I could see issues for 
things like keywords (IsExpression for example).


But what do I know. I've never written a programming language. I 
just hope the end result isn't wait for another!


Ross