r/functionalprogramming • u/Gohonox • Sep 14 '25
Question Convince me that functional programming is as useful to me as OOP and introduce me to this world
Okay, first of all, I don't exactly know what functional programming is. I've seen a feature or two in some programming language, but I've never really immersed myself in this world.
One more bit of context I wanted to share about myself: I work with data analysis and machine learning, especially in Python with Polars and lots of plots. But in my free time and on personal projects, I like to use languages other than Python (I don't really like the nature of scripted implicit non-typed languages for my personal projects, I only use Python for data or AI related stuff)... My personal projects include languages like Go and Java, and I have to admit that I like (and find useful) object-oriented programming, I can think intuitively with it. And about my projects, I like to do desktop utilities softwares, and that's exactly why I like non-power users being able to use my applications with no problem.
And I'm always researching other technologies as well, but one criterion I take very (really very) seriously is that I don't care much about theoretical/academic arguments about X or Y (I see this happening a lot with functional paradigm nerds talking about Haskel, but whenever I try to look, I don't see much immediate practical use for it for me...); I'm more serious about whether I can be productive in practice with something and whether I can actually produce a complete product with it. And by 'complete product' I mean not only that it has its features and an incredible engine or API running in the background, but that it has a graphical GUI and a user who isn't a power user can also use my applications easily.
So please, help me understand and introduce me to this functional programming world:
- What is functional programming exactly? What is the productivity flow like with the functional paradigm versus the object-oriented one?
- Can I be really productive with a functional language (or not necessarily the language, but using only the functional paradigm) in the sense that I explained before of being able to produce a 'complete product'?
- If the answer to the previous question is yes, then what languages should I look at using perhaps as my functional language?
Thank you for your time!
12
u/paul_schnapp Sep 15 '25 edited Sep 15 '25
Even if you don't think you'll use it for a main language, I would recommend learning more about it to give you different perspectives on OOP and to be able to utilize more of the features that have been making their way to OOP languages of late (e.g. lambdas, higher-order functions).
19
u/saideeps Sep 14 '25
There is nothing natural about oops or functional programming. It will be harder to build an end to end product with Haskell because of the lack of and the extent of supporting libraries you’d need. Every major programming language borrows something from functional programming. If a language has higher order functions, anonymous functions, partial functions and lazy evaluation that’s most of what makes up a functional programming language. If you need a language to quickly spin up an entire service then pick up Scala. Like anything it’ll take up time to build the muscle for a new programming paradigm. There is no easy or quick and dirty way to learn about functional programming. E.g, Spark, Kafka are large scale widely deployed and influential services that were originally written in Scala and weren’t just theoretical exercises in functional programming.
8
u/codeconscious Sep 15 '25
For the record, I'm also relatively new to functional programming. I come from a C# background, so I jumped into F# out of curiosity (and have been loving it). As such, I'll respond to the points I feel I can handle.
I'm similar. I work with Ruby on Rails at work, but mostly work with .NET privately, largely for similar reasons.
I'd say yes. I can only speak with my limited experience with F#, but I'd say I've been about as productive in it as I have been in C#, and I've produced some small CLI programs for myself with it. That said, if you search online, you'll find people that have done much more with it as well.
I think FP principles will help improve your code in other languages too.
I know where you're coming from. However, in my (again, limited) experience, you don't need to understand those concepts to get started building programs. Perhaps knowing more mathematical or advanced topics helps at more advanced levels, but I don't think such knowledge is necessary at all to get started with and enjoy FP. (I certainly don't have much. ^_^')
I think you'll pick up what you need to once you jump in. Some common things—like function currying and the
ResultandOptiontypes—will come to you naturally with practice. Granted, some, like usingfolds instead of normal looping, might take some time to adjust to. (Maybe this year's Advent of Code would be a good challenge?)I don't have the experience to answer this well. Each language will have its strengths and weaknesses, I suppose, so it likely depends on the language you select and on what you wish to build too.
However, personally, I've greatly enjoyed my time with F#, and it's currently my favorite language; but I do come from a C# background, so perhaps it was a more natural fit for me than it would be for you since I already have familiarity with .NET. (Note that F# is functional first, but still allows OOO when desired as well, though I haven't used it for that yet. Depending on whom you speak with, this is likely a plus or a minus, but I think it's a plus for me.)
That said, F# is Microsoft's version of OCaml, so I can suggest looking into F# or OCaml.
In any case, I hope you get a lot of recommendations and try out a language or two. I can attest that learning about functional programming invigorated my passion for programming.
7
u/poopatroopa3 Sep 15 '25
7
u/dannuic Sep 15 '25
Speaking as someone who has used functional programming in his day to day for over a decade:
I have mostly used scala and elixir in production, with a small amount of F#, but, and this is important, I also use the same principles in python because I'm often passing python code off to colleagues that don't know any other languages. It makes this handoff exceedingly simple because there's no unnecessary levels of abstraction and you can walk through the code completely in a 30 minute handoff. The real and most obvious advantage to using FP in a professional setting is that it makes collaboration dead simple. If you're working on a big project, dividing to the workload is both simple and elastic because you just need to write units without needing to understand large scale state mutations. If you're working on smaller projects, then you keep the project simple and easy to follow, which means easy to share.
I've worked in C++ and other OOP languages before transitioning to FP, so this is my comparative experience.
4
u/Beneficial-Win-6533 Sep 15 '25
biggest improvement for me is that alot lesser mental overhead when thinking about what parts of the program might fail.
4
u/[deleted] Sep 15 '25
Why not to try functional techniques in Python first? There is a book about it, Functional Python Programming by Steven F. Lott .
7
u/c__beck Sep 15 '25
I'm still pretty new to FP myself, so take everything here with a grain of salt, but:
FP is basically about using a bunch of small, single-use pure functions to create your app. The output of one function is used as the input of the next. Rinse and repeat.
Pure functions are useful b/c they have the same output given the same input. This way the code is more readable. Of course, you can't avoid impure functions—HTTP calls are impure since the network could lag, the server could be down, etc, so you won't always get the same output for the same input. But you encapsulate your impurities in helper "objects" like monads and functors that help allow you to continue the function pipe even if you get an error.
As one user recently said to me: "The great thing about functional programming is that there's only one design pattern: The Pipeline."
Yes, you can be just as productive with a FP language as you can be with an OOP language. It's just a different tool to achieve the same result. Your web apps still make HTTP calls and your destop apps still read/write to the file system. You just do it functionally instead of object-like.
I know there are a whole lot more but I don't know them all. I'm a JS dev who tried Elixir and Go and didn't like 'em so 🤷
3
u/Jamb9876 Sep 14 '25
FP is pretty simple in theory. You have a function. It always returns the output of what it did. Everything it needs to do the operation is passed into the function.
So you don’t have for loops. Use recursion. This one can be debated but that is the general thing, recursive functions are better.
So if you go by the simple definition your functions are easily multithreaded since you don’t have anything to block.
Things like logs and databases are special situations but you won’t have classes, just functions.
Most modern languages have FP parts to them. If you have a pipeline, so filter -> map For example is a common approach as you can pipeline these functions easily
JavaScript has concepts for this as does Kotlin and C#. Rust and elixir/erlang are good languages.
3
u/Tecoloteller Sep 15 '25 edited Sep 15 '25
I'm also still relatively new to functional programming in earnest but I do what I call a functional-lite style, as in, imperative programming withthout mutation of state and emphasizing pure functions. Programming in a non -mutating way with pure functions and minimizing/handling side effects explicitly seems to me like a decent description of FP, there's a lot more you can do but they're built on this foundation.
I'll list a couple bullet points that I think are heavily in functional programming's favor:
Functional programming doesn't have to be about super obscure theoretical stuff. It can definitely make use of that stuff and I think that stuff is delightful on its own, but you don't have to bust out Monads right out the gate. Functional programming just feels like it can help keep things flat and local in a way that very encapsulation heavy or inheritance heavy OOP would have a harder time doing. Enums and sum types are a great example of where FP and OOP differ. Relying on an exact knowledge of how many variants are in an enum would be a big violation of encapsulation in OOP, but you get a huge pay off in expressive power if you use sum types especially with an exhaustive checking compiler, plus especially in code others don't directly interface with, you get to control when new variants are added and at a certain point probably won't be added mamy new variants. And if you really need an unbounded number of variants, an interface does just fine.
Tldr; immutability, simplification of control flow (everything should be data or a function taking your data and giving you new data), and Algebraic data types are the killer features of FP that you can get a lot out of right now.
And for language recs, FP seems to be a spectrum. Most languages aren't Haskell, a more FP-y language like the BEAM languages (Elixir/Gleam/Erlang) or Scala or Clojure (both on the JVM, the latter a LISP) or Elm is way more likely to have better support for all of the above I mentioned. I think Rust is excellent though maybe a little too imperative for some folk's taste. I highly recommend something with built in support for exhaustive checking of enum/discriminated union/sum types (Typescript can be made to do this with some tricks I think, Go with enough boilerplate that it's unfortunately just not really worth it, even Java and Kotlin on the JVM have this with Records + Sealed interfaces). If you wanna do something webby, functional style TS or Elm would be a good option (I really like this book https://mostly-adequate.gitbook.io/mostly-adequate-guide), if you like something like desktop apps then a JVM language would be a good choice. Other people will have more useful advice on things like Ocaml or the BEAM languages tho.
-3
u/Nemeczekes Sep 15 '25
You could literally ask chat gpt those questions.