Reputation: 33
I have read several interesting C#/F# comparisons here on stackoverflow. So, first of all, thanks to all contributors!
There is a lot of praise for F#, reasons for preferring C# are a little harder to come by. Anyway, I am still not sure which one to go for this small and simple "real world application": simulating a school of herring.
I don't know functional programming (yet), but from an OO perspective, some of the design seems straight forward: Make a Fish class, and derive these classes from it: Herring, Predator, Prey. Each should have properties such as position, direction and speed.
There will be a lot of traversing through collections: Every small time increment, each Fish-object will check its environemnt and update its actions.
I don't know yet if this will be CPU intensive enough that I will care about multi-processing, but maybe, so F# sounds good there.
I am sure I will be spending a lot of time on prototyping and exploring - I hear F# is good for that.
From what I have read, C# is better for GUI, but there will not be much of that. Plotting some curves would be nice, but I would prefer to send most of the results to an open Excel sheet, or to a database. Not sure how C# and F# differ regarding Excel/databases.
Anyway, this project just seems so Object Oriented - could C# be better for this project despite the points in favour of F# mentioned above? Or??
Edit: Just wanted to say thanks for all the comments, very useful and interesting, hope it helps someone else too. One of the things I find interesting is that although F# is multi-paradigm, everyone seems to prefer C#'s approach to OO, despite for example this comparison. (Btw, I am going to learn F#.)
Upvotes: 3
Views: 721
Reputation: 243051
This sounds like an application that can be written using both of the styles. Using F# seems appropriate and this is probably a good application for learning the F# language and functional programming.
Regarding the architecture, you wrote:
I don't know functional programming (yet), but from an OO perspective, some of the design seems straight forward: Make a Fish class, and derive these classes from it: Herring, Predator, Prey. Each should have properties such as position, direction and speed.
Functional programming isn't all that different. It emphasisez working with concrete types (and you don't use inheritance that often), so you would probably define distinct types such as Herring
and Predator
with similar properties. Then you would create lists of herrings and list of predators and perform step-by-step simulation of the two types separately.
Coincidentally, I wrote a similar simulation with "animals" and "predators" as a sample for my functional programming book (in both C# and F#). The source is freely available (look for Chapter 14), so you may find that as a useful inspiration (the sample also demonstrates parallelism). Using Excel from F# is also perfectly possible (in exactly the same way as in C#) and example is also available in my book (see source code for Chapter 13).
In general, solving the problem in F# using functional programming will require slightly different point of view, and you'll probably need to spend more time experimenting, but it seems like the problem could nicely benefit from some F# features (and it is a good chance to learn something new).
Upvotes: 4
Reputation: 66573
There is no reason you can’t write the algorithmic code in F# and still have your GUI in C#. Just put the algorithms in a library written in F#, and write the GUI application in C#, referencing the library.
Upvotes: 15
Reputation: 10650
It sounds like a good chance to try both, either by mixing them or by doing the whole thing in both languages, so you can experience both of them and learn all the differences between functional and OO programming. By the way, you can do OO in F# since it's a hybrid language, and you can do functional programming in C#, with limitations of course.
Also, you shouldn't have any real problems with DB access or Excel integration from either language.
Upvotes: 4
Reputation: 44307
I'm on the fence.
If (as you imply by the way you wrote the question) you're wanting an object oriented solution for your simulation, then of course C# will be the better tool, because it's OO by nature.
But, if you're willing to consider a functional solution, then you'll find F# will be better - because it's functional by nature.
Upvotes: 3