Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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 OO) could cause a lack of cohesion in the design. Is that correct?

share|improve this question
    
How can you use them in the same project? Do you mean the same solution? –  insta Feb 23 '12 at 15:53
    
Not the Microsoft Definition of project but the more general definition –  Tom Squires Feb 23 '12 at 16:05

3 Answers 3

up vote 16 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
2  
Anonymous types are not really an F# principle. May be you mean to refer to type inference (what the var keyword does in C#) whereby the compiler guesses what type you are referring to. This is used throughout F#. –  Mongus Pong Nov 8 '11 at 11:14
1  
I would use F# for the easy async capabilities. However, the TPL has made it quite easy to do that in C# by itself. If you were to embed a language for scripting though, I would definitely use F# for the parsing of that. –  Jetti Dec 7 '11 at 17:33

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.