16

I know you can use C# and F# together in the same project however I'm not sure if its a good idea to do so.

It seems to me that mixing two very different coding styles (functional vs OOP) could cause a lack of cohesion in the design. Is this correct?

wonea
  • 141
Tom Squires
  • 17,835

3 Answers3

23

There's nothing wrong with mixing languages in a product as long as you use each appropriately and they "play nice" together.

If there is part of your project that would be best coded using a functional language then it makes sense to code it in F#. Similarly for C#.

What would be pointless (at best) would be mixing languages for the sake of it.

ChrisF
  • 38,948
  • 11
  • 127
  • 168
0

Yes I agree with ChrisF. Also C# currently already incorporates F# principles, such as anonymous types:

var unitanon = new[]
{
    new { Field1="new car", Field2 = 1},
    new { Field1="old car", Field2 = 20} 
};

That said, I personally think it's a step backward in code readability, though it is very convenient.

wonea
  • 141
0

It seems to me that mixing two very different coding styles (functional vs OO) could cause a lack of cohesion in the design. Is that correct?

I don't think you'll get a "lack of cohesion". Each language has strengths and weaknesses. Combining them on a common-language run-time lets you get closer to the best of both worlds. With C# and F#, you just want to make sure you use the intersection of the two languages at the interface between the two in your solution.

J D
  • 2,332