J
Jon Skeet [C# MVP]
(It would really help if you'd get your newsreader to wrap at 76
characters, btw.)
Created unnecessarily, I would say. The extra type isn't adding any
value to the world except to expose the methods. Now you can expose the
methods which *effectively* you want to act on the original data, but
directly on that original data.
What genuine benefit is MyLinq giving, over extension methods? It adds
cruft when using LINQ, for no benefit.
Not to my mind. The point is that you're not saying that instances of
MyLinq are actually "special" in any way; it doesn't indicate anything
different about the data. It merely allows you to add the methods.
Extension methods give a different way of doing that, without using up
the one shot at inheritance. In fact, by not deriving from anything
your MyLinq now isn't specializing anything anyway, it's wrapping
something - again, for no reason.
On the fly no
That's the thing though - extension methods lets you effectively give
"extra powers" to everything, precisely *because* you don't want to
limit it to particular implementations.
True, but you also don't write
new Math(1).Sin() which is *much* more akin to what you're doing.
The fact that square root operates on a single number? There's no
logical reason to have two values involved.
Funnily enough, with extension methods you could make a.Sqrt() work
easily for all the built in numeric types (and any extras you wanted to
add).
And it'll still be uglier than what we've got, IMO.
No problem - but I really think you ought to immerse yourself deeper in
future before dismissing things as awful.
characters, btw.)
Axel Dahmen said:Exactly. Please refer to my reply below which comes without the
constructor call. Yet I'd prefer to have that constructor call. It
keeps the programmer bear in mind that a new object is being created.
Created unnecessarily, I would say. The extra type isn't adding any
value to the world except to expose the methods. Now you can expose the
methods which *effectively* you want to act on the original data, but
directly on that original data.
What genuine benefit is MyLinq giving, over extension methods? It adds
cruft when using LINQ, for no benefit.
Adding methods is in fact a kind of specialization.
Not to my mind. The point is that you're not saying that instances of
MyLinq are actually "special" in any way; it doesn't indicate anything
different about the data. It merely allows you to add the methods.
Extension methods give a different way of doing that, without using up
the one shot at inheritance. In fact, by not deriving from anything
your MyLinq now isn't specializing anything anyway, it's wrapping
something - again, for no reason.
On the fly no
other analogy comes to my mind than this, rather depicting, one:
A dog that is able to fly, say 100m, is a specialization of a standard
dog. No new property, just a new member function [myDog.fly(100);].
It's still a dog, but a special one... Having another, standard, dog
fly 100m by, say, using a catapult will not make that dog a
specialized one. It's still a standard dog that's flying. And people
should see that you're using a catapult to make him fly. And it
shouldn't be made too easy to use these catapults to make a normal
dog fly like a flying dog. Although both look the same while flying,
theresult, when they come down again in the end, will be different
when it comes to maintaining/debugging the dogs.
That's the thing though - extension methods lets you effectively give
"extra powers" to everything, precisely *because* you don't want to
limit it to particular implementations.
Well, you don't write "Math.Plus(a, b);", you write "a + b".
True, but you also don't write
new Math(1).Sin() which is *much* more akin to what you're doing.
So what's so ugly about writing "a.Sqrt(b);" ?
The fact that square root operates on a single number? There's no
logical reason to have two values involved.
These functions could
become members of INumber<T> or something which every number value
should implement. Operators are operators, no matter how they're
written.
Funnily enough, with extension methods you could make a.Sqrt() work
easily for all the built in numeric types (and any extras you wanted to
add).
You're absolutely right. I don't know about LinQ yet (that's why I
regretfully need to leave this thread in order to return learning)
and I copied the collection in my example. But please keep in mind
that I hacked it in in just two or three minutes. Just put the actual
LinQ Extension Method bodies in there and everything will be as with
LinQ which does all the same on the first Extension Method argument.
And it'll still be uglier than what we've got, IMO.
I'm looking forward to read into it!
Actually, as I just wrote, I regretfully need to leave this thread in
order to continue learning .NET 3.5. Perhaps I'll revisit it again
over the weekend, but that will be the final for me.
Thanks, Jon, for taking the time and arguing with me. Talking to you
is always a pleasure.
No problem - but I really think you ought to immerse yourself deeper in
future before dismissing things as awful.