I'm learning functional programming and face the following confusion when applying it to my C# projects:
- I begin by writing pure, static functions and use function composition.
After the code reaches a certain size, I realize some of these functions tend to "cluster" about some types. For example, there exist >5 functions having the same type as parameter.
Next step, my object-oriented background takes over and I move these functions to this type (class) as methods. As a result, their signatures simplify and they often become more cohesive. However, I lose the benefits of functional style.
I've grown very fond of functional approach, but I cannot convince myself that my initial code was better above. Which approach would you prefer in this situation (in C# or another mixed language)?
Related: Design in "mixed" languages: object oriented design or functional programming?
class MyType { }
class Functions
{
public static void X(MyType t) { }
public static void Y(MyType t) { }
public static void Z(MyType t) { }
public static void T(MyType t) { }
public static void U(MyType t) { }
}
class Class1
{
public MyType T { get; private set; }
public Class1(MyType t) { T = t; }
public void X() { }
public void Y() { }
public void Z() { }
public void T() { }
public void U() { }
}