UDAs - Restrict to User Defined Types?

2012-11-07 Thread Walter Bright
Started a new thread on this. On 11/7/2012 3:05 AM, Leandro Lucarella wrote: > OK, that's another thing. And maybe a reason for listening to people having > more experience with UDAs than you. > > For me the analogy with Exceptions is pretty good. The issues an conveniences > of throwing anything

Re: UDAs - Restrict to User Defined Types?

2012-11-07 Thread Adam D. Ruppe
I think restricting to user types makes sense because the type is how you'd actually do anything with it. My figuring is you'd generally do something like this: foreach(t; __traits(getAttributes, foo)) static if(is(t == WhatICareAbout)) { // use it } And if what you care about is

Re: UDAs - Restrict to User Defined Types?

2012-11-07 Thread Tobias Pankrath
On Wednesday, 7 November 2012 at 23:18:41 UTC, Walter Bright wrote: Why would you look in module X for an attribute that you have no reason to believe applies to symbols from X? How would an attribute for module X's symbols leak out of X on their own? What if you are using two different librar

Re: UDAs - Restrict to User Defined Types?

2012-11-07 Thread David Nadlinger
On Wednesday, 7 November 2012 at 23:18:41 UTC, Walter Bright wrote: One last thing. Sure, string attributes can (and surely would be) used for different purposes in different libraries. The presumption is that this would cause a conflict. But would it? There are two aspects to a UDA - the attri

Re: UDAs - Restrict to User Defined Types?

2012-11-07 Thread Simen Kjaeraas
On 2012-11-08, 00:18, Walter Bright wrote: Started a new thread on this. On 11/7/2012 3:05 AM, Leandro Lucarella wrote: > OK, that's another thing. And maybe a reason for listening to people having > more experience with UDAs than you. > > For me the analogy with Exceptions is pretty goo

Re: UDAs - Restrict to User Defined Types?

2012-11-07 Thread Timon Gehr
On 11/08/2012 12:18 AM, Walter Bright wrote: Started a new thread on this. On 11/7/2012 3:05 AM, Leandro Lucarella wrote: > OK, that's another thing. And maybe a reason for listening to people having > more experience with UDAs than you. > > For me the analogy with Exceptions is pretty good.

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jacob Carlborg
On 2012-11-08 00:18, Walter Bright wrote: There's another aspect to this. D's UDAs are a purely compile time system, attaching arbitrary metadata to specific symbols. The other UDA systems I'm aware of appear to be runtime systems. This implies the use cases will be different - how, I don't re

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread simendsjo
On Thursday, 8 November 2012 at 09:05:31 UTC, Jacob Carlborg wrote: I think we should only allow user defined types marked with @attribute, i.e. @attribute struct foo {} @attribute class foo {} @attribute interface foo {} @attribute enum foo {} And so on. Or struct @foo {} interface @foo {}

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Simen Kjaeraas
On 2012-11-08, 11:56, simendsjo wrote: On Thursday, 8 November 2012 at 09:05:31 UTC, Jacob Carlborg wrote: I think we should only allow user defined types marked with @attribute, i.e. @attribute struct foo {} @attribute class foo {} @attribute interface foo {} @attribute enum foo {} And so

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jacob Carlborg
On 2012-11-08 11:56, simendsjo wrote: Or struct @foo {} interface @foo {} enum @foo {0 etc That syntax looks a bit backwards to me. What if I want to annotate the attribute. @serializable struct @foo {} Looks a bit confusing which is the name of the attribute and the which is the attached

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread David Nadlinger
On Thursday, 8 November 2012 at 13:19:29 UTC, Jacob Carlborg wrote: That syntax looks a bit backwards to me. What if I want to annotate the attribute. Sorry, I could not resist: http://cdn.memegenerator.net/instances/400x/29863604.jpg David

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread simendsjo
On Thursday, 8 November 2012 at 13:19:29 UTC, Jacob Carlborg wrote: On 2012-11-08 11:56, simendsjo wrote: Or struct @foo {} interface @foo {} enum @foo {0 etc That syntax looks a bit backwards to me. What if I want to annotate the attribute. @serializable struct @foo {} Looks a bit confus

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jacob Carlborg
On 2012-11-08 17:26, David Nadlinger wrote: Sorry, I could not resist: http://cdn.memegenerator.net/instances/400x/29863604.jpg Hehe, exactly :) -- /Jacob Carlborg

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jacob Carlborg
On 2012-11-08 17:53, simendsjo wrote: I guess it depends. I find it easier to see that it's an attribute, especially when you annotate it. But it's harder to grep for. Is foo an attribute or not? @serializable @xmlRoot @attribute @displayName("foo") struct foo {} Is foo an attri

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread simendsjo
On Thursday, 8 November 2012 at 17:20:39 UTC, Jacob Carlborg wrote: On 2012-11-08 17:53, simendsjo wrote: I guess it depends. I find it easier to see that it's an attribute, especially when you annotate it. But it's harder to grep for. Is foo an attribute or not? @serializable @xmlRoot

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Nathan M. Swan
On Wednesday, 7 November 2012 at 23:18:41 UTC, Walter Bright wrote: Started a new thread on this. On 11/7/2012 3:05 AM, Leandro Lucarella wrote: > OK, that's another thing. And maybe a reason for listening to people having > more experience with UDAs than you. > > For me the analogy with Excepti

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Nick Sabalausky
On Thu, 08 Nov 2012 10:05:30 +0100 Jacob Carlborg wrote: > > I think we should only allow user defined types marked with > @attribute, i.e. > > @attribute struct foo {} > @attribute class foo {} > @attribute interface foo {} > @attribute enum foo {} > > And so on. > I completely agree. I real

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread H. S. Teoh
On Thu, Nov 08, 2012 at 10:45:05PM -0500, Nick Sabalausky wrote: > On Thu, 08 Nov 2012 10:05:30 +0100 > Jacob Carlborg wrote: > > > > I think we should only allow user defined types marked with > > @attribute, i.e. > > > > @attribute struct foo {} > > @attribute class foo {} > > @attribute inter

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Adam D. Ruppe
On Friday, 9 November 2012 at 03:45:11 UTC, Nick Sabalausky wrote: the *one* thing I hate about D ranges is that they don't force you to explicitly say "Yes, I *intend* this to be an InputRange" (what are we, Go users?). Just a note, of course it still wouldn't *force*, but maybe it'd be a go

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Nick Sabalausky
On Thu, 8 Nov 2012 20:17:24 -0800 "H. S. Teoh" wrote: > > Actually, I just thought of a solution to the whole duck-typing range > thing: > > struct MyRange { > // Self-documenting: this struct is intended to be a > // range. > static assert(isInput

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Walter Bright
On 11/8/2012 8:18 PM, Adam D. Ruppe wrote: On Friday, 9 November 2012 at 03:45:11 UTC, Nick Sabalausky wrote: the *one* thing I hate about D ranges is that they don't force you to explicitly say "Yes, I *intend* this to be an InputRange" (what are we, Go users?). Just a note, of course it stil

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jonathan M Davis
On Thursday, November 08, 2012 21:10:55 Walter Bright wrote: > Many algorithms (at least the ones in Phobos do) already do a check to > ensure the inputs are the correct kind of range. I don't think you'll get > very far trying to use a range that isn't a range. > > Of course, you can always still

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread H. S. Teoh
On Thu, Nov 08, 2012 at 11:51:29PM -0500, Nick Sabalausky wrote: > On Thu, 8 Nov 2012 20:17:24 -0800 > "H. S. Teoh" wrote: > > > > Actually, I just thought of a solution to the whole duck-typing range > > thing: > > > > struct MyRange { > > // Self-documenting: this struct is int

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Walter Bright
On 11/8/2012 9:24 PM, Jonathan M Davis wrote: So, I really don't see this as a problem. Neither do I. BTW, there's no compiler magic in the world that will statically guarantee you have a non-buggy implementation of a range.

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jonathan M Davis
On Thursday, November 08, 2012 21:49:52 Walter Bright wrote: > BTW, there's no compiler magic in the world that will statically guarantee > you have a non-buggy implementation of a range. That's what unit tests are for. :) - Jonathan M Davis

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Andrej Mitrovic
On 11/9/12, H. S. Teoh wrote: > Then all input ranges will have to explicitly declare they are an input > range thus: Or: Change definition of isInputRange to: --- template isInputRange(T) { enum bool isInputRange = (__attributes(T, RequiresInputRangeCheck) &&

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread H. S. Teoh
On Thu, Nov 08, 2012 at 09:37:00PM -0800, H. S. Teoh wrote: > On Thu, Nov 08, 2012 at 11:51:29PM -0500, Nick Sabalausky wrote: [...] > > Those are only half-solutions as they only prevent false-negatives, > > not false-positives. Plus, there's nothing to prevent people from > > forgetting to do it

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread H. S. Teoh
On Thu, Nov 08, 2012 at 10:03:03PM -0800, Jonathan M Davis wrote: > On Thursday, November 08, 2012 21:49:52 Walter Bright wrote: > > BTW, there's no compiler magic in the world that will statically > > guarantee you have a non-buggy implementation of a range. Yeah, that's one major missing feature

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Walter Bright
On 11/8/2012 10:20 PM, H. S. Teoh wrote: But of course that's just splitting hairs. "Let's not go splittin' hares!" -- Bugs Bunny

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Nick Sabalausky
On Thu, 08 Nov 2012 21:10:55 -0800 Walter Bright wrote: > > Many algorithms (at least the ones in Phobos do) already do a check > to ensure the inputs are the correct kind of range. I don't think > you'll get very far trying to use a range that isn't a range. > It can't check semantics. If some

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Nick Sabalausky
On Thu, 8 Nov 2012 21:37:00 -0800 "H. S. Teoh" wrote: > > IOW, you want the user-defined type to declare that it's an input > range, and not just some random struct that happens to have input > range like functions? > Yes. > What about modifying isInputRange to be something like this: > >

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jonathan M Davis
On Friday, November 09, 2012 01:44:51 Nick Sabalausky wrote: > On Thu, 08 Nov 2012 21:10:55 -0800 > > Walter Bright wrote: > > Many algorithms (at least the ones in Phobos do) already do a check > > to ensure the inputs are the correct kind of range. I don't think > > you'll get very far trying t

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Nick Sabalausky
On Thu, 08 Nov 2012 21:24:49 -0800 Jonathan M Davis wrote: > On Thursday, November 08, 2012 21:10:55 Walter Bright wrote: > > Many algorithms (at least the ones in Phobos do) already do a check > > to ensure the inputs are the correct kind of range. I don't think > > you'll get very far trying to

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Andrej Mitrovic
On 11/9/12, H. S. Teoh wrote: > Yeah, that's one major missing feature from D/Phobos/etc.: a mixin > template called EliminateBugs that will fix all your program's bugs for > you. I think that should be the next top priority on D's to-do list! ;-) Considering you can do a string import of the mod

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jonathan M Davis
On Friday, November 09, 2012 01:53:40 Nick Sabalausky wrote: > Looking at one set of interfaces in isolation, sure the chances might > be low. (Just like the chances of name collisions when hygeine is > lacking, and yet we thankfully have a real module system, instead of C's > clumsy "Well, it shou

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jacob Carlborg
On 2012-11-09 07:20, H. S. Teoh wrote: Well, unittests are a runtime check, and they don't *guarantee* anything. (One could, in theory, write a pathological pseudo-range that passes basic unittests but fail to behave like a range in some obscure corner case. Transient ranges would fall under tha

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jonathan M Davis
On Friday, November 09, 2012 08:21:38 Jacob Carlborg wrote: > On 2012-11-09 07:20, H. S. Teoh wrote: > > Well, unittests are a runtime check, and they don't *guarantee* > > anything. (One could, in theory, write a pathological pseudo-range that > > passes basic unittests but fail to behave like a r

Re: UDAs - Restrict to User Defined Types?

2012-11-08 Thread Jacob Carlborg
On 2012-11-09 08:28, Jonathan M Davis wrote: But the types are already tested by the templat constraints and the fact that they compile at all. It's the functions' runtime behaviors that can't be tested, and no language can really test that at compile time, whereas unit test _do_ test the runtim

Re: UDAs - Restrict to User Defined Types?

2012-11-09 Thread Jonas Drewsen
On Friday, 9 November 2012 at 07:29:28 UTC, Jonathan M Davis wrote: On Friday, November 09, 2012 08:21:38 Jacob Carlborg wrote: On 2012-11-09 07:20, H. S. Teoh wrote: > Well, unittests are a runtime check, and they don't > *guarantee* > anything. (One could, in theory, write a pathological > p

Re: UDAs - Restrict to User Defined Types?

2012-11-09 Thread Adam D. Ruppe
On Friday, 9 November 2012 at 05:11:05 UTC, Walter Bright wrote: Many algorithms (at least the ones in Phobos do) already do a check to ensure the inputs are the correct kind of range. There's two annoyances there: 1) the error messages can be godawful, not giving you any indication why. It's

Re: UDAs - Restrict to User Defined Types?

2012-11-09 Thread Adam D. Ruppe
On Friday, 9 November 2012 at 05:25:12 UTC, Jonathan M Davis wrote: Given that a range requires a very specific set of functions, I find it highly unlikely that anything which isn't a range will qualify as one. I've had it happen to me several times. Let me show you some code from my dom.d:

Re: UDAs - Restrict to User Defined Types?

2012-11-09 Thread Jonathan M Davis
On Friday, November 09, 2012 14:14:01 Adam D. Ruppe wrote: > Of course, they all have something in common: an open opDispatch. > But that's a valid D feature so surely I'm not the only one using > it. Okay. I can see it happening there, and alias this could cause similar problems, but if you're a

Re: UDAs - Restrict to User Defined Types?

2012-11-10 Thread deadalnix
Le 08/11/2012 11:56, simendsjo a écrit : On Thursday, 8 November 2012 at 09:05:31 UTC, Jacob Carlborg wrote: I think we should only allow user defined types marked with @attribute, i.e. @attribute struct foo {} @attribute class foo {} @attribute interface foo {} @attribute enum foo {} And so o

Re: UDAs - Restrict to User Defined Types?

2012-11-10 Thread deadalnix
Le 08/11/2012 19:55, simendsjo a écrit : On Thursday, 8 November 2012 at 17:20:39 UTC, Jacob Carlborg wrote: On 2012-11-08 17:53, simendsjo wrote: I guess it depends. I find it easier to see that it's an attribute, especially when you annotate it. But it's harder to grep for. Is foo an attrib

Re: UDAs - Restrict to User Defined Types?

2012-11-10 Thread deadalnix
Le 08/11/2012 01:11, Timon Gehr a écrit : On 11/08/2012 12:18 AM, Walter Bright wrote: Started a new thread on this. On 11/7/2012 3:05 AM, Leandro Lucarella wrote: > OK, that's another thing. And maybe a reason for listening to people having > more experience with UDAs than you. > > For me the

Re: UDAs - Restrict to User Defined Types?

2012-11-10 Thread deadalnix
Le 09/11/2012 07:53, Nick Sabalausky a écrit : On Thu, 08 Nov 2012 21:24:49 -0800 Jonathan M Davis wrote: On Thursday, November 08, 2012 21:10:55 Walter Bright wrote: Many algorithms (at least the ones in Phobos do) already do a check to ensure the inputs are the correct kind of range. I don'

Re: UDAs - Restrict to User Defined Types?

2012-11-10 Thread Artur Skawina
On 11/09/12 07:41, Nick Sabalausky wrote: > Of course, it'd be even nicer still to have all this wrapped up in > some language sugar (D3? ;) ) and just do something like: > > struct interface InputRange { > // ... *declare* .empty, .front, .popFront here > } > > struct interface ForwardRange