r/functionalprogramming • • Apr 25 '23
Question I want to learn fn programming
Someone can tell me which are the arguments for learning functional programming? (I want to structure better my function)
I’m a JS developer.
12
Upvotes
11
u/Parasomnopolis Apr 25 '23
There's an introductory functional programming for JS course on Frontend Masters: https://frontendmasters.com/courses/functional-first-steps/
6
u/kinow mod Apr 25 '23
I think the classical paper recommended by many is "Why Functional Programming Matters". But if you are new to programming, and especially if you are using JS in a company without other FP programmers and with an imperative code base, then you may find it challenging to understand the paper and also to find ways to apply FP in JS.
I would suggest you look for existing posts in this subreddit with the flair JavaScript. If you use old.reddit.com, it should be on the top of the subrredit frontpage. Here's the link to save you some clicks: https://old.reddit.com/r/functionalprogramming/wiki/index
EDIT: forgot to add the link to the article, sorry: https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf (the link to the paper is also on the subreddit sidebar ->)
3
u/PriorTrick Apr 25 '23
Check out Rescript/ReasonML, bucklescript, Ocaml. Really powerful and perfect for JS devs
2
u/kaas93 Apr 26 '23
Some of the key practical benefits of functional programming over other paradigms is purity (no side effects) and immutability by design. This tends to eradicate a class of bugs you might encounter otherwise.
Seeing as you're used to JavaScript, this guide may be helpful to get you started. However, to properly get a grasp of things, doing some code katas in Haskell for example, will really force you to rethink how you code.
2
u/WizardOfAngmar Apr 26 '23
I suggest you having a look into ReScript. I’m currently learning it and writing some articles about it, from a JS/TS developer perspective.
I’ll leave the link here, feel free to check it out: https://mauriziovacca.blogspot.com/2023/03/functional-friday-discovering-rescript.html
Best!
2
u/Agiliway Apr 27 '23
For many years now, there has been a lively debate about which programming style is the best. Some people prefer the declarative approach, while others swear by the imperative paradigm. Both styles have their advantages, so whether you are an experienced programmer looking to expand your skills and knowledge by learning new programming languages, or a business owner in need of software development services that can meet all of your company's requirements, our article about comparison OOP and FP will be useful for you.
2
u/mckahz Apr 28 '23
Essentially FP boils down to using more pure functions. If you wanna do FP in JS then just use more pure functions, and less impure functions. Otherwise things like higher order functions, closures, and even Monads all exist in JS to some degree, and there are plenty of good resources just one google search away.
If you really wanna delve deep into FP, use Elm. It's a great replacement for JS for most frontend needs. It's also pure FP, which I recommend if you wanna really get a feel for FP. Otherwise there's a popular talk somewhere on YouTube called "functional programming in JavaScript" and it's pretty good.
The main issue is that the lack of types and good notation in JavaScript make it quite difficult to talk about a lot of FP concepts, so you'll often see talks about FP use a notation a bit closer to maths (Haskells notation), so if you want to go deep into strong typing / pure FP / immutability / etc. It will help to work in a suitable notation, like Elm of F#.
2
u/nmarshall23 Apr 25 '23
If you want to learn Functional programming, my suggestion is to use Haskell to solve projecteuler.net problems. They are all pure math problems, that are too large for you do by hand.
Learn You a Haskell for Great Good!
1
u/CodeMeister02 Apr 28 '23
I had to learn Scheme for a university course, and I really enjoyed functional programming. The language is really old but really simple, so it was easy to learn. It's not as complex (or typesafe) as something like Haskell. I thought it was a good way to try functional programming without sinking a ton of time into a complex language. Scheme is a dialect of Lisp, and you may have an easier time finding documentation for something like CommonLisp if you want to try something easy-ish without investing a ton of time.
-1
u/[deleted] Apr 25 '23
Get started in JavaScript. https://frontendmasters.com/learn/functional-javascript/
I work through the list.
This one helped me the most
https://frontendmasters.com/courses/hardcore-js-v2/