Re: .NET generics & the .NET framework: not generic enough?
From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 07/18/04
- Next message: Thomas: "Re: ASP.NET Image Resizing"
- Previous message: Eyal Cohen: "Transaction error"
- In reply to: Daniel O'Connell [C# MVP]: "Re: .NET generics & the .NET framework: not generic enough?"
- Next in thread: Daniel O'Connell [C# MVP]: "Re: .NET generics & the .NET framework: not generic enough?"
- Reply: Daniel O'Connell [C# MVP]: "Re: .NET generics & the .NET framework: not generic enough?"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 18 Jul 2004 10:13:43 -0500
Daniel,
> primatives alone. I do wish there was a way to express that you want int,
> uint, byte, sbyte, short, ushort, long, ulong, string, decimal, double or
> float *only* in a generic
Why? What if I create a BetterInt32? (aka a family of types like SqlInt32 in
System.Data.SqlTypes) that due to CLS requirements BetterInt32 cannot be a
generic class, so I need to do it the "old fashion way". Remember that
Generics are not CLS compatible, however you are free to use generics
internal to your project, even if the public interface is CLS compatible.
Why should generic math be limited to Int32 and not my BetterInt32?
Also as I mentioned elsewhere in this thread. int uses an IL opcode for
addition, while decimal uses an overloaded operator, so you have an
exception from the start, so enabling a constraint for just the "primitives"
is probably more work then it needs to be or should be, as it would need to
support both overloaded operators & opcodes...
One of the reasons for struct & overloaded operators is to enable us as
designers to define our own "simple data". For example Martin Fowler's
Range & Quantity patterns, both of which I would consider "simple data", and
I could see a need to enable them for generic math!
http://www.martinfowler.com/ap2/
http://martinfowler.com/ieeeSoftware/whenType.pdf
Just a thought
Jay
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:OAh%23OnJbEHA.1764@TK2MSFTNGP10.phx.gbl...
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:%2349uNcIbEHA.2944@TK2MSFTNGP11.phx.gbl...
> > Daniel,
> > I gave the link more for an example of an existing suggestion, not as a
> > suggestion I specifically endorse.
> >
>
> Sorry, I didn't mean to be harsh. I'm just rather annoyed with the
operator
> thing. I think I've posted that same general reply a dozen times now.
>
> > I like IArithmetic<T>, as it seems to be the "easier" route. (the KISS
> > principal). If only Int32 implemented it ;-) also IArithmetic<T> is in
> > keeping with IComparable<T>.
> Ya, that would help termendously by helping to constrain generics to
> primatives alone. I do wish there was a way to express that you want int,
> uint, byte, sbyte, short, ushort, long, ulong, string, decimal, double or
> float *only* in a generic. It'd help out *alot* in data situations where
you
> want to create classes that handle simple data. But, alas, that is a pipe
> dream right now. IArithmetic wouldn't help with everything, but it'd make
> numbers simpler.
>
> >
> > I agree that an actual "operator +" constraint may need to get too fancy
> > to
> > be useful, especially when you consider it needs to work across
languages.
> > But then again Microsoft has a lot of talented people working for them,
> > and
> > if we (the users) keep throwing it about in the publics, hopefully
> > something
> > usable can be created...
> >
> Well, I for one am not a huge fan of operator overloading in general, but
it
> is frustrating not to be able to perform basic mathematics with generics.
It
> certainly takes away the ability to *easily* do something like the stream
in
> STL, where the size type could be defined in the template.
>
>
>
>
- Next message: Thomas: "Re: ASP.NET Image Resizing"
- Previous message: Eyal Cohen: "Transaction error"
- In reply to: Daniel O'Connell [C# MVP]: "Re: .NET generics & the .NET framework: not generic enough?"
- Next in thread: Daniel O'Connell [C# MVP]: "Re: .NET generics & the .NET framework: not generic enough?"
- Reply: Daniel O'Connell [C# MVP]: "Re: .NET generics & the .NET framework: not generic enough?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|