9

I'm a .Net and Angular developer who's been working with OO languages throughout my education and work history. Lately I've been thinking about spending some time with one of the functional programming languages, namely Haskell, to try and get a feel for what functional programming is all about.

My main reservations are on whether Haskell is a good language to start with and whether it is actually used anywhere in the industry. I guess the industry use question is more broad to target all functional languages. I have never personally met anyone who worked with functional programming language in their day today job. I'm basically trying to justify learning a functional programming language instead of another OO library or framework, relevant to my field.

4
  • 4
    If your language(s) support them, start by just using more functional constructs, like map() and reduce(), in your everyday programming. A much easier introduction than learning a whole new language.
    – user949300
    Commented Jan 25, 2020 at 7:12
  • I worked for a bit more than a year as front end dev, who used procedural programming for say 95% of my code. I used anonymous functions to create namespaces to avoid globals and occasionally used objects for making plugins(revealing module pattern). I went around 3k to 5k lines of jquery code and it was maintainable.
    – user106313
    Commented Jan 26, 2020 at 2:09
  • "the industry" ... which industry?
    – Useless
    Commented Jan 27, 2020 at 16:07
  • Recommended: find a recent recording of "Functional Principles for Object Oriented Development" by Jessica Kerr.
    – Theraot
    Commented Oct 19, 2020 at 5:16

4 Answers 4

18

Since you write that you're a .NET developer and you don't even mention F#, odds are that you're a C# developer. In that case, I'd strongly suggest that you learn F# first. It's another .NET language, and it's a great stepping stone for anyone coming from C#.

In itself, it's a great FP language, but it also offers full interoperability with the existing .NET ecosystem. Besides its FP features, it also offers a full set of OOP features. This enables you to learn gradually.

  1. Learn the F# syntax, but keep on writing object-oriented code. You can do this in a week or two.
  2. Start learning functional concepts. For instance, once you understand maps and folds, replace your for loops with those.
  3. Learn more abstract functional ways of thinking. Repeat from here.

You can take each of these steps in small increments, all the time staying productive.

Once you have a good grasp of the functional parts of F#, Haskell can be a good next step. I've met many people who tried to learn Haskell 'from scratch'. Most people report that they give up because the learning curve is too steep.

I came to Haskell via some years of F# and found it a natural next step.

There's lots of free learning resources for F#, the most famous of which is probably F# for fun and profit. If you come from C#, another great introduction to F# is Real-World Functional Programming. It juxtaposes examples in C# and F# so that you can compare.

As far as I can tell, there aren't a lot of jobs where you get to program exclusively in F# or Haskell, but learning either will likely still make you a better programmer, so I'd highly recommend it.

I've written F# professionally, but never Haskell. I've written a lot of Haskell semi-professionally; I'm self-employed and invest significant time in doing so, but no-one has ever paid me to program in it. Still, I consider it highly worthwhile.

1
  • 2
    A coworker used to solve problems from Project Euler using Haskell to learn it. I tried to do the same but... "ooooh...Netflix!" (Only half-joking...) I wanted to do that for F# as it seemed like a good way to toy with the language without getting into anything big. Commented Jan 28, 2020 at 12:44
8

I have never personally met anyone who working with functional programming language in their day today job.

I am paid to write OCaml, AMA!

My main reservations are on whether Haskell is a good language to start with and whether it is actually used anywhere in the industry.

Haskell isn't a great language for your first language, but it is a very solid language for your fourth language or so. It has a fair number of guides (such as the very nice learnyouahaskell), a stable compiler, and is very representative of a functional programming language.

That said, it is used by almost nobody (relatively speaking) in the industry.

I'm basically trying to justify learning a functional programming language instead of another OO library or framework, relevant to my field.

Functional programming techniques are commonly used these days in most languages. Learning a language more devoted to functional programming will help you better understand those techniques - how to use them, as well as where their strengths and weaknesses lie compared to object-oriented or procedural programming. It's another tool for your box, and will help you program better even if you never ship a line of code in the language itself.

3
  • 2
    "Functional programming techniques are commonly used in C# and JavaScript" and Java, and Python, and and and (the list goes on and on). Programming languages move to be multi-paradigm and try to include the best of all worlds.
    – Polygnome
    Commented Jan 25, 2020 at 9:28
  • 3
    Almost nobody? Plenty of people use it and write about it. Sources, please. Also, for .Net, might recommend F# Commented Jan 25, 2020 at 15:06
  • 3
    @D.BenKnoble - so doing a quick search on indeed for Haskell shows 540 jobs. Java has 70,155, Python has 74,628, C# has 32,383...
    – Telastyn
    Commented Jan 25, 2020 at 18:24
3

I could also suggest you to look at Scala, which, on its front page, literally says:

"Scala combines object-oriented and functional programming in one concise, high-level language."

Arguably, if you come from an OO background, like most of us, I'd dare say, then using Scala makes sense, if anything for the sake of experimentation. Also, the main reason is that in all their docs, references, even papers by Odersky, they do put emphasis on using functional constructs and on thinking functionally, which might be all you really need so you can do a smooth transition to start writing .NET in a more functional style.

Moving to Java, looking at how the Streams API is implemented as well how annotations like @FunctionalInterface enable you to write functional code, and, if interested reading through the Java Enhancement Proposals regarding functional features can give you a great feel how things work under the hood which can definitely help you in shifting your mind.

1
  • 3
    I'll second this. I personally failed at learning Haskell twice because of how monads are shoved in your face right away. Scala lets you get there gradually. After learning Scala, Haskell finally made sense to me. Commented Jan 29, 2020 at 20:04
1
  • If your main interest is in broadening your programming mind and skill set, more academic languages like Haskell, ML or Clean are probably for you.
  • Haskell is actually used in industry, but not on a very broad range (e.g. Facebook has a group doing Haskell, Standard Chartered maintains an own Haskell dialect, etc.).
  • If you are more interested in practical languages that you can use in day jobs, object-functional languages Scala, OCaml and F# are probably at par language-wise, so you rather pick one depending on the platform, F# for .NET, Scala for the JVM, and OCaml for Unix/compiled. Even C# allows a fair amount of functional programming.
  • Scala jobs are fairly wide-spread, job market growing from what I see, OCaml is very limited (e.g. Jane Street Capital), F# is used far less than it deserves.
  • If the JVM is a serious option there is also Clojure as a modern, object-functional Lisp, which gained a lot of traction in the job market, part. in the US (I held a full-time Clojure job for one year).
  • If you are more inclined towards UI development you may abandon Angular and try Elm, or even PureScript which is Haskell for JavaScript runtimes (browsers/Node.js).
  • Having mentioned UIs, don't underestimate the potential to introduce functional languages through specific applications that use them as their "DSL", e.g. build tool Fake (using F#), or load testing tool Gatling (using Scala).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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