J
jehugaleahsa
Hello:
I was reading another post and saw an argument (sort of) that brought
up a good question.
I have written a fairly large library of algorithms that occur in
programming all the time. It mixes the C++ STL and the Power
Collections Algorithms class.
Recently a coworker of mine asked me what the deal was with anonymous
methods. I didn't quite know how to explain them. I told them that the
delegate is a wrapper around a method that allows another piece of
code to call it whenever it is needed. It is like providing the guts
and the rest is taken care of. I know that is a bad definition.
Anyway, I went on to show him my Algorithms class and the 140+ methods
inside of it. He was completely lost. When I showed him what it looked
like to use my library, he completely lost-er it.
Now, the question for this post is this:
Is procedure code (like a foreach loop) more readable than a
functional/generic code? For me, either is like reading straight
through. But for newcomers, it appears to be a big burden. I see
functional coding as a way of separating action, iteration and data.
Is this as desirable as it sounds and is it worth making code less
readable.
Another question: In design patterns there is what is called the
Visitor pattern. Here, every item in a collection implements an
interface and it is 'accessed' when that item is iterated over. Is
this a better way to handle an operation on a collection than simply
calling a functional method that does the iteration for you and you
provide the delegate? Can a delegate be polymorphic as required for
them to be comparable? Here, the data and action are combined and
separated from the iteration.
Since generics are fairly new to C# and less powerful than C++
templates, I think it is a good time to ponder whether moving toward
functional programming is advisable for C#, etc.
Thanks for your opinions,
Travis
I was reading another post and saw an argument (sort of) that brought
up a good question.
I have written a fairly large library of algorithms that occur in
programming all the time. It mixes the C++ STL and the Power
Collections Algorithms class.
Recently a coworker of mine asked me what the deal was with anonymous
methods. I didn't quite know how to explain them. I told them that the
delegate is a wrapper around a method that allows another piece of
code to call it whenever it is needed. It is like providing the guts
and the rest is taken care of. I know that is a bad definition.
Anyway, I went on to show him my Algorithms class and the 140+ methods
inside of it. He was completely lost. When I showed him what it looked
like to use my library, he completely lost-er it.
Now, the question for this post is this:
Is procedure code (like a foreach loop) more readable than a
functional/generic code? For me, either is like reading straight
through. But for newcomers, it appears to be a big burden. I see
functional coding as a way of separating action, iteration and data.
Is this as desirable as it sounds and is it worth making code less
readable.
Another question: In design patterns there is what is called the
Visitor pattern. Here, every item in a collection implements an
interface and it is 'accessed' when that item is iterated over. Is
this a better way to handle an operation on a collection than simply
calling a functional method that does the iteration for you and you
provide the delegate? Can a delegate be polymorphic as required for
them to be comparable? Here, the data and action are combined and
separated from the iteration.
Since generics are fairly new to C# and less powerful than C++
templates, I think it is a good time to ponder whether moving toward
functional programming is advisable for C#, etc.
Thanks for your opinions,
Travis