I can see it working for AddNew(), but considering the number of lists that may require paramters as well as factory methods. Wouldn't it be easier to register a generic factory class that uses new T(int) rather than reflection to generate a class instance? You get both compiletime and runtime insurance that the constructor atleast works right. Assuming of course that runtime specification of a generic type argument is possible in a trivial manner. If taking a Type object and getting a generic List<T> out of it is a trial...I think there is a considerable lack of specification there as well. There are anumber of things I'd like to see, static methods\conversions on enums isn't a bad feature, I'd like to know how usable the iterators are going to be, I doubt we'll be able to use full fledged coroutines directly but will be required to use IEnumerator classes, but its better than nothing. Stronger class contracts(beyond interfaces) would be appreciable for the development of componentized\modular apps, but you can't stuff everything into a single langauge...we'll see waht comes. ----- Original Message ----- From: "Thomas Tomiczek" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, October 24, 2003 4:10 AM Subject: Re: [ADVANCED-DOTNET] C# generics constraints syntax
For the WHY - propably to facilitate the AddNew () behavior that most lists define. I can see a new (string, int) to be useable at times, but frnakly - even the new() contrain t in itself is GREAT. What I would prefer is the ablity to define static methods and conversions for enums. I sincerely miss the ability of an enum to have static methods attached to it. I have some enums that "represent" a numeric value, but not directly. Stuff like values in the enum being 3.2, 3.5, 3.8 - and sometimes I only need the "3"part out of it. A static method would allow me to say Int I = Enumname.ToGenericInt(enumvalue) :-) Just in case someone at MS reads this. Right now I have to put all these little methods into external utility methods. Thomas Tomiczek THONA Software & Consulting Ltd. (Microsoft MVP C#/.NET) > -----Original Message----- > From: Moderated discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED] On Behalf Of > Daniel O'Connell > Sent: Freitag, 24. Oktober 2003 03:02 > To: [EMAIL PROTECTED] > Subject: Re: [ADVANCED-DOTNET] C# generics constraints syntax > > On further research(read the c# 2.0 spec doc up on msdn), it > doesn't appear that constructor constaints exist beyond a > default constructor(new()) or how to actually use that > constraint(one would assume you don't have to use reflection > in this situation). However I find that to be a glaring > omission that only default constructors can be defined, any > one have any comments as to why? > > > ----- Original Message ----- > From: "Thong (Tum) Nguyen" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Thursday, October 23, 2003 5:51 PM > Subject: Re: [ADVANCED-DOTNET] C# generics constraints syntax > > > > You're probably right. I'm just toying with alternatives > to the "where" > > clause. > > > > One advantage of the where clause is that it actually looks > quite nice > > if you place it on a separate line... > > > > public class TreeDictionary<K, V> : ICollection > > where K : IComparable > > where V : Object > > > > > > BTW, what does the "new()" do? > > > > ^Tum > > > > > -----Original Message----- > > > From: Moderated discussion of advanced .NET topics. > > > [mailto:ADVANCED- [EMAIL PROTECTED] On Behalf Of Daniel > > > O'Connell > > > Sent: Friday, 24 October 2003 11:26 a.m. > > > To: [EMAIL PROTECTED] > > > Subject: Re: [ADVANCED-DOTNET] C# generics constraints syntax > > > > > > I think convoluting the syntax is a much worse choice > than adding a > > > new keyword. Adding ontop of that the chances of error (<T: (Bar, > > > Bax, > new(), > > > S> > > > which is incorrect and is an easy mistake to make). I > don't know how > > > specific constructor constraints can get, but having a > whole list of > them > > > would make it very easy to not realize you didn't close > the matching (. > > > I find it much cleaner to do, assuming inheritance: > > > > > > public class Dictionary<T,S> : IEnumerable where T : Bar, > Bax, new() > > > where S : IComparable, new() > > > > > > compared to something like > > > > > > public class Dictionary<T : (Bar, Bax, new()), S : (IComparable, > > > new())> > : > > > IEnumerable > > > or > > > public class Dictionary<T : Bar & Bax & new(), S : IComparable & > > > new()> > : > > > IEnumerable > > > > > > (of the two, I prefer the latter actually) > > > > > > The C# syntax as it currently stands is simpler in my > mind, probably > > > understandable to an extent for amateurs, its easy determine what > > > constraint is on what member, and there are no paranthetical > > > screwups that could > get > > > in > > > the way. It also makes figuring out what Dictionary > derives from and > what > > > the constraints are, just by looking for the : and where keywords, > instead > > > of having to do a full fledged mind-parse. > > > > > > I am not a huge fan of the where clause, but I don't > think the other > > > syntaxes suggested solve the biggest underlying problem, which > > > basically is that generics make class declarations much larger, > > > especially as the argument list starts to grow. Imagine 7 > or 8 type > > > arguments with constraints, unlikely as it may be, with > ANY existing > > > syntax...doesn't look pretty does it? > > > > > > > > > ----- Original Message ----- > > > From: "Thong (Tum) Nguyen" <[EMAIL PROTECTED]> > > > To: <[EMAIL PROTECTED]> > > > Sent: Thursday, October 23, 2003 4:46 AM > > > Subject: Re: [ADVANCED-DOTNET] C# generics constraints syntax > > > > > > > > > > I think something along the lines of > > > > > > > > <T : (Bar, Bax), S> would be a reasonable alternative > to the "where" > > > clause. > > > > > > > > ^Tum > > > > > > > > > -----Original Message----- > > > > > From: Moderated discussion of advanced .NET topics. > [mailto:ADVANCED- > > > > > [EMAIL PROTECTED] On Behalf Of Dominic Cooney > > > > > Sent: Thursday, 23 October 2003 1:27 p.m. > > > > > To: [EMAIL PROTECTED] > > > > > Subject: Re: [ADVANCED-DOTNET] C# generics constraints syntax > > > > > > > > > > FWIW, the design of the Java language has gone in the other > direction; > > > the > > > > > syntax is: Foo<T extends Bar, U extends Baz>. I am > not sure how > > > multiple > > > > > constraints are specified (T extends Bar & Baz, IIRC). > > > > > > > > > > What is VB.NET doing? > > > > > > > > > > Dominic Cooney > > > > > > > > > > -----Original Message----- > > > > > From: Moderated discussion of advanced .NET topics. > > > > > [mailto:[EMAIL PROTECTED] On > Behalf Of Daniel > > > O'Connell > > > > > Sent: Thursday, 23 October 2003 9:05 AM > > > > > To: [EMAIL PROTECTED] > > > > > Subject: Re: [ADVANCED-DOTNET] C# generics constraints syntax > > > > > > > > > > I'd say readability first, personally. It'd be alot easier to > > > > > read > > > > > > > > > > public class Dictionary<KeyType,ValType> where KeyType : > IComparable, > > > > > ICollection, IAnotherThing, ValueType : IComparable, > IDictionaryValue, > > > > > IAnotherRestriction > > > > > > > > > > than > > > > > public class Dictionary<KeyType : IComparable, ICollection, > > > IAnotherThing, > > > > > ValueType : IComparable, IDictionaryValue, > IAnotherRestriction>; > > > > > > > > > > Beyond that, I imagine parsing is easier this way. It > would be > > > > > tough > > > to > > > > > determine what the second type name is, should it be named > > > ICollection, > > > > > IAnotherThing, ValueType, etc? > > > > > > > > > > ----- Original Message ----- > > > > > From: "Thong (Tum) Nguyen" <[EMAIL PROTECTED]> > > > > > To: <[EMAIL PROTECTED]> > > > > > Sent: Wednesday, October 22, 2003 5:50 PM > > > > > Subject: [ADVANCED-DOTNET] C# generics constraints syntax > > > > > > > > > > > > > > > > Hey folks, > > > > > > > > > > > > Can anyone think of a reason why the constraints > syntax is this: > > > > > > > > > > > > public class Dictionary<KeyType, ValType> where KeyType : > > > IComparable > > > > > > > > > > > > rather than this: > > > > > > > > > > > > public class Dictionary<KeyType : IComparable, ValType> > > > > > > > > > > > > ? > > > > > > > > > > > > The former adds an additional (unreserved?) keyword to the > language > > > and > > > > > > locates two related things apart from each other > (the generic > > > parameter > > > > > & > > > > > > its constraint). > > > > > > > > > > > > There's probably a good reason I've overlooked. > > > > > > > > > > > > All the best, > > > > > > > > > > > > ^Tum > > > > > > > > > > > > =================================== > > > > > > This list is hosted by DevelopMentorR > http://www.develop.com > > > > > > NEW! ASP.NET courses you may be interested in: > > > > > > > > > > > > 2 Days of ASP.NET, 29 Sept 2003, in Redmond > > > > > > http://www.develop.com/courses/2daspdotnet > > > > > > > > > > > > Guerrilla ASP.NET, 13 Oct 2003, in Boston > > > > > > http://www.develop.com/courses/gaspdotnet > > > > > > > > > > > > View archives and manage your subscription(s) at > > > > > http://discuss.develop.com > > > > > > > > > > =================================== > > > > > This list is hosted by DevelopMentorR http://www.develop.com > > > > > NEW! ASP.NET courses you may be interested in: > > > > > > > > > > 2 Days of ASP.NET, 29 Sept 2003, in Redmond > > > > > http://www.develop.com/courses/2daspdotnet > > > > > > > > > > Guerrilla ASP.NET, 13 Oct 2003, in Boston > > > > > http://www.develop.com/courses/gaspdotnet > > > > > > > > > > View archives and manage your subscription(s) at > > > > > http://discuss.develop.com > > > > > > > > > > =================================== > > > > > This list is hosted by DevelopMentor. http://www.develop.com > > > > > NEW! ASP.NET courses you may be interested in: > > > > > > > > > > 2 Days of ASP.NET, 29 Sept 2003, in Redmond > > > > > http://www.develop.com/courses/2daspdotnet > > > > > > > > > > Guerrilla ASP.NET, 13 Oct 2003, in Boston > > > > > http://www.develop.com/courses/gaspdotnet > > > > > > > > > > View archives and manage your subscription(s) at > > > > > http://discuss.develop.com > > > > > > > > =================================== > > > > This list is hosted by DevelopMentorR > http://www.develop.com NEW! > > > > ASP.NET courses you may be interested in: > > > > > > > > 2 Days of ASP.NET, 29 Sept 2003, in Redmond > > > > http://www.develop.com/courses/2daspdotnet > > > > > > > > Guerrilla ASP.NET, 13 Oct 2003, in Boston > > > > http://www.develop.com/courses/gaspdotnet > > > > > > > > View archives and manage your subscription(s) at > > > http://discuss.develop.com > > > > > > > > > > =================================== > > > This list is hosted by DevelopMentorR > http://www.develop.com NEW! > > > ASP.NET courses you may be interested in: > > > > > > 2 Days of ASP.NET, 29 Sept 2003, in Redmond > > > http://www.develop.com/courses/2daspdotnet > > > > > > Guerrilla ASP.NET, 13 Oct 2003, in Boston > > > http://www.develop.com/courses/gaspdotnet > > > > > > View archives and manage your subscription(s) at > > > http://discuss.develop.com > > > > =================================== > > This list is hosted by DevelopMentor(r) http://www.develop.com NEW! > > ASP.NET courses you may be interested in: > > > > 2 Days of ASP.NET, 29 Sept 2003, in Redmond > > http://www.develop.com/courses/2daspdotnet > > > > Guerrilla ASP.NET, 13 Oct 2003, in Boston > > http://www.develop.com/courses/gaspdotnet > > > > View archives and manage your subscription(s) at > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentor(r) http://www.develop.com > NEW! ASP.NET courses you may be interested in: > > 2 Days of ASP.NET, 29 Sept 2003, in Redmond > http://www.develop.com/courses/2daspdotnet > > Guerrilla ASP.NET, 13 Oct 2003, in Boston > http://www.develop.com/courses/gaspdotnet > > View archives and manage your subscription(s) at > http://discuss.develop.com > > =================================== This list is hosted by DevelopMentor� http://www.develop.com NEW! ASP.NET courses you may be interested in: 2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor� http://www.develop.com NEW! ASP.NET courses you may be interested in: 2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet View archives and manage your subscription(s) at http://discuss.develop.com
