Axel Dahmen said:
I'm not too deep into Linq, I'm discussing about Extension Methods
here. Yet, AFAIK, Linq only works on IEnumerable derived classes. As
does my example... So what in fact would you do in both cases?
LINQ to Object only works on IEnumerable<T> (and IEnumerable to some
extent) but LINQ itself is completely type-agnostic. For example, Marc
Gravell and I recently wrote a "push" version of LINQ by implementing
the same set of operators as extensions on a different interface.
I agree with you. From the developer's point of view I don't see a
difference either (except for where to take functionality from, where
to find it etc.), but from the designer's point of view Extension
Methods are a huge gate for proliferating bad coding.
Do you really not see any benefit in being able to effectively add
behaviour to interfaces without the interface implementor having to do
any work themselves?
Just want to say that adding layers of hierarchy doesn't necessarily
lack performance. Basically additional code is only executed in
constructors (and destructors). But - apart from any additional code
being executed - it's not more than just a function call to the base
class's constructor/destructor. Anything else would have been
executed as well by using any other possible concept in the world.
Well, virtual methods can't be inlined of course. I agree it's not
likely to be significant in many cases. Personally I find inheritance
has more of a *design* penalty than a *performance* penalty.
Actually you don't need to. As you've seen from my example I've used
a MyLinq generic to do the job. There wasn't even inheritance
involved here. Still, in case you wouldn't need the derived class,
just use the base class. There is absolutely no reason that would
keep you from creating and using base classes as long as they are not
declared as being abstract.
But this means we can *only* use LINQ to Objects with your class,
Please refer to my other reply where I gave an example of how to keep
internal behaviour solid without sealing a class.
Don't forget method *hiding* as well as overriding. If I were able to
declare:
FooString x = new FooString(...);
then x.Equals may well have nothing to do with the normal string.Equals
behaviour.
I'm very happy with string having been sealed. I just wish classes were
sealed by default.
Yep, syntactical sugar for having ignored OOA. My humble opinion still.
I don't think you can really claim it's your "humble" opinion when you
write things like:
"Extension Methods in .NET is a slap in the face of all serious
software engineers."
That's not humble at all.
Because, for instance, when implementing Extension Methods in a
workgroup, debugging will become a mess. You can't boil an error down
to a class's implementation. It's impossible to narrow the search.
You've just have to debug the *whole* code.
When debugging, I don't normally say "I'll look at all the code in a
certain class" - I say "I'll look at all the code in a particular flow
of execution". That will *often* include code from multiple classes;
this is no different.
Helper classes are usually a good example for procedural code
disguised as OOD.
Not in my view.
I'd regard any such as bad. They don't help. I
can't discuss with you on your example without having seen your code.
But if you'd like to add a function to SqlConnection then why don't
you just create a derivate class then?
Inheritance appears to be your answer to everything, despite its
massive issues when introducing new behaviour.
For a start, you can't always decide which type you'll actually get. If
you're using an API which returns SqlConnection, what are you going to
do? You could write a wrapper class instead, I suppose - but that's a
different answer and not significantly different to writing helper
methods.
Inheritance is great for *specializing* behaviour, but not for writing
behaviour which is valid for *all* instances of a particular class.
Extension methods are great for the latter, and work with interfaces
too.
Or why are you using it so massively at all? It's a technical class
that should be hidden somewhere in a data access layer class
hierarchy.
You make it sound as if the code in the DAL doesn't really exist. Sure,
SqlConnection shouldn't be used outside the DAL - but within the DAL,
it may be used fairly heavily.