Tell me more ×
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.

This is a long story but I will try to summarize it as best I can. We are a .NET shop that writes software for a variety of different types of funds. For example, we write health claims management software, pension management software, 401(k) software and some other financial-type things. Now we are entering a new realm: derivatives and quantitative analytics type of work, which seems very exciting. This is something that is coming down in the next 8-12 months I've been told. Now, I have learned some functional programming on my own, mainly just superficial glances at various languages via this book but never really dug deep into it. Now, since we are a .NET shop I was thinking F# might be a good choice, because we could potentially leverage some .NET libraries and existing knowledge possibly. My question is where to start? I am having an exceedingly difficult time trying to figure out if I should go with Haskell, Erlang, Scala, F#, etc. They all seem very interesting and capable and quite frankly this might be a good chance to break out being so Microsoft dependent.

Has anyone had a similar situation? If so, what was your experience making the jump to functional and what did you choose and why? I know this is kind of a big question but I don't know any developers that are using functional methods right now so I have nowhere else to turn other than Googling incessantly and finding flame wars everywhere on the best functional language.

Thanks very much indeed

Cheers, Steven

share|improve this question

5 Answers

up vote 7 down vote accepted

Prototype, prototype, prototype! Take one bit of business functionality that you think requires functional programming and try the various languages out and see if they really do give you the benefits and the interoperability that you're looking for.

share|improve this answer
Good advice and I will heed it, in fact I am doing an Erlang install right now to give it a go. – Steven Ellliott Jr May 6 '11 at 14:15

The first question you really need to answer truthfully is why you are considering using a functional language. If you can't justify a business reason for the switch then you shouldn't do it. In other words, wanting to introduce a new framework, language or other new technology into your work environment just because you want to learn it or because it seems like the next "cool" thing is definitely a mistake. So you need to first truthfully ask yourself what the motivation is.

If you really feel you need a functional language to solve a particular problem, and assuming most of the mainstream functional languages will meet your requirements, then I would go with the most mature and the one with the largest user community. Erlang is a good choice and meets both of these requirements, however, in a purely ms/.NET environment, I can understand using F#.

share|improve this answer
1  
@ennukiller - I can definitely see that functional programming would be a good choice for us and I'm not going to lie - I'd also love to use it just for the sheer intellectual stimulation it will provide. We are going to be doing massive amounts of calculations and I want to take advantage of multi-core. Also, it's imperative that every mathematical function be proven correct, I understand that may be easier with functional. – Steven Ellliott Jr May 6 '11 at 14:14
If you need proofs, pure functional programming is best. Some suggestions here are for functional add-ons to imperative languages - they might be more familiar, but won't give you provably correct code. In the presence of side effects, you cannot use the fact that x=x ('referential transparency'), and you have to prove that the x later in the code still holds the same value as earlier. In some languages, for example, it can happen that x:=3; y:=10; x:=add(x,x); results in an x which is not 6 and a y which is not 10. To prove your functions correct in this context is impractical. – AndrewC Sep 3 '12 at 21:30

I'd strongly agree with F# for a shop with an existing .Net codebase, much as I would strongly agree with Scala for a shop with an existing Java codebase.

Functional programming is a tool like any other. Used well, and integrated with how you're already developing code, it can make you more productive by making it easier to reason about what your code is doing. Switching languages is far from free, however, so your best bet is a solution that lets you use as much of your existing code as possible for as long as possible into the transition. The surest way to fail to introduce a new language into your environment, after all, will be to tell your coworkers that they have to rewrite everything they've got so far in order to see the benefits of a change that, at this point, you're still trying to sell them on.

share|improve this answer

I would recommend starting functional programming without also learning a new language right away. It just makes it more difficult if you're trying to learn a new paradigm when you're also trying to get to grips with the syntax of a new language.

Of course, languages that have been specifically developed to do functional programming will have some advantages (such as having specific constructs such as comprehensions and making data structures immutable by default), but in general the biggest step to make is change your thinking to a functional style. C# is great for doing that.

Basically, you just stop changing the state of your code. I've done this using Java and it's even easier with C# because you have lambdas. Once you get the hang of that style and a feeling for what it's good for, it will be very easy to pick up a functional language (regardless of whether it's F# you choose or Erlang) and be immensely productive with it.

share|improve this answer
+1: I agree with you. I have also started to code in a more functional style in Java and C++ (using more final and const variables, breaking up complex operation using function composition, and so on). I think this has definitely improved my programming style in Java and C++. After a while, when one feels ready to go further, one can try out a functional language (Haskell, Ocaml, SML, Lisp, Scala, F#, etc.) – Giorgio Apr 7 '12 at 16:32

If all you want is to learn and understand functional programming, then just install IronPython and focus on the functional features in Python. At worst, you will learn a tool that can be integrated with C# to cut down the number of lines of code in an application and help you deliver more bugfree products ahead of schedule.

Have a look at DaBeaz's presentations about generators for an example of how functional approaches in Python can simplify complex things http://www.dabeaz.com/generators/

Other than that, I think that you would be wise to invest some time with Scala. It runs on .NET in beta mode, so you can install it and use it today for learning purposes, and by the autumn, it will be in release mode for .NET. This means that you can write code in Scala that is portable across the JVM and .NET. And, since Scala is based around Actors and message passing, it is very, very easy to build an application made out of several separate programs running on several separate machines. When you add the .NET/JVM portability to the mix, then there is another aspect to consider. You could have one application that leverages both 3rd party Java libraries and 3rd party .NET libraries without messing around with developing protocols to make them communicate. Both processes would be written in Scala, and would use Scala remote messaging (remote actors) to communicate. Check out the Akka, library which seems like it will eventually become part of Scala's standard library judging by what Typesafe.com are doing.

share|improve this answer
+1: For mentioning Scala and its availability on different platforms. Question: will akka replace the current actor implementation in Scala? Or will the two exist side by side? – Giorgio Apr 7 '12 at 16:37
Not sure if Akka will replace the current Scala actors anytime soon, but Scala creator Martin Odersky has joined with Akka creator Jonas Boner in the company Typesafe. They are heavily promoting Scala with Akka and now with the Play framework. So it is likely that the focus of development will be on Akka. If you are just learning actors with Scala, it would be best to focus on Akka first. – Michael Dillon Apr 8 '12 at 2:39
Thanks a lot for the information! I took a look at actors in Scala but only a very superficial one up to now. – Giorgio Apr 8 '12 at 7:59

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.