r/functionalprogramming • u/1234filip • Mar 14 '24
Question Learning functional programming with a new language or stick to TypeScript?
I've got quite a lot experience in TypeScript and C#. Before I knew about functional programming I was already using some patterns like higher-order functions(which are everywhere in TypeScript) and stuff like immutability when using LINQ.
I'm currently taking a course at university that will dedicate some of its hours to functional programming, we already covered lambda calculus. But it is more of a theoretical course so there won't be much programming.
So I'm torn: should I just study up on functional programming concepts and just apply it to TypeScript or learn a completely new language like Elixir that is really designed for FP?
My end goal is to improve the ease of writing code and maybe do some projects with it(so ecosystem is important and TS and C# have got quite big ones). I'm not that interested in mathematical and academic applications for now.
17
u/[deleted] Mar 14 '24 edited Mar 14 '24
Your other option is to learn F#. You will have access to all C# libs but keep in mind that you will have to use OO in F# to use them. But F# will give real features that are built for functional first programming.
And despite what you might have read F# is NOT for just stats/academic applications. It can do anything that C# can.
4
u/digitizemd Mar 14 '24
If you do stick with typescript, effect is a library, based on Scala ZIO, that tries to make FP a bit more developer friendly.
4
u/tesilab Mar 14 '24
My understanding is that what you gain in Elixir in FP, you might lose in terms of types.
Learning FP I would take Haskell as an overall model,and consider trying something like purescript and purerl (if you are looking for a BEAM language, it compiles purescript to erlang instead of javascript, so you scratch a BEAM itch at the same time.
Purescript is very haskell inspired, but for practical reasons is strict rather than lazy, and will not have identical syntax.
4
u/Collaborologist Mar 15 '24 edited Mar 18 '24
Surprised to not yet see Clojure recommended. Warren Buffet himself has bet about a billion$ on Nubank, which is Clojure at core. It runs anywhere a JVM can run which covers most business and enterprise deployments. It has good Java interop. To me it is functional made practical. If you look at Stack surveys of SWEs you'll see that senior long-tenured and well paid SWEs prefer F# and Clojure, and you know how you will land wrt to THAT divide.
3
u/jhartikainen Mar 14 '24
If you have the time I would suggest learning a new language. Elixir is a good language and very practical. Haskell would be another good choice, but it is likely to take you a bit longer to learn it.
Although both Elixir and Haskell have a different syntax from TS and such, the concepts you learn will still translate and improve your general understanding of programming.
Using something you're familiar with to learn is also perfectly fine - I just think that there are benefits from learning languages which differ from what you are used to, as they tend to require approaching things a bit differently and thus improve your skills overall.
3
u/GunpowderGuy Mar 14 '24
Depends on what type of learner you are. Whether you can juggle multiple new skills such as learning a new language and a new skill.
"maybe do some projects with it" What kinds of projects are you interested in?
I am currently coding a fighting game in idris2
3
u/amirrajan Mar 14 '24
You may want to try Fable and ClojureScript. They transpile to JavaScript and you’ll get exposure to FP in the context of both a static and dynamic language
2
u/AlexBreizh56 Mar 14 '24
If ypu want to use fp with ts you Can take a look a this lib https://gcanti.github.io/fp-ts/
2
u/MissunderstoodOrc Mar 16 '24
I would say you will need to learn function programming, from a language that is purely functional. You can take back the lessons learned, and with a new way of thinking back to common languages.
The reason why is that, using functional concept introduced to imperative language are helpful but not impactful enough. Most of the time the language only has few very primitive functional concepts, and you cannot do that much with it. But in pure functional languages, you will code in very different way, and be able to use "wild" functional concepts that will blow your mind. Then you can take this new intuition an improve your code in any other language, and see places in code where using the functional concepts from a language is a good idea.
Haskell changed my way of thinking a lot. And it had impact on code in any language I have used since.
2
u/Kobleren Mar 17 '24
Clojure??? :-)
2
u/peni4142 Apr 04 '24
Maybe you should choose a language that supports functional programming concepts. TypeScript and C# don’t. Currying is excellent, and you should learn about monads.
I learned functional programming with Haskell. Setting that up can be painful, but if you use VSCode, it is automated by an extension, if I remember correctly.
Haskell is also strong-typed, which could be a new experience for you.
Disclaimer: I barely don't know anything about other functional programming languages.
2
u/fabrisimo Mar 17 '24
I just ran into this new functional programming language named GLEAM. I'm definitely going to try it. Runs using Elixir or JS. Check it out!
https://www.youtube.com/watch?v=9mfO821E7sE&t=43s
2
u/John-The-Bomb-2 Mar 14 '24 edited Mar 14 '24
I'm going to say something that is probably going to get downvoted, but functional programming is a rabbit hole that beyond a certain depth/point stops being helpful for getting real world jobs. After a certain point, it becomes more of a personal intellectual thing than something other people can use you for in industry. I went down the rabbit hole and got books on Category Theory (a branch of math used in pure functional programming) and looked at pure functional programming libraries like Scala's Cats (short for "Categories", as in "Category Theory") and ScalaZ. Simply put, yeah that stuff can be intellectually interesting, but corporations aren't really using it, and it is pretty much impossible to get a job using it (with very few exceptions, Cats and ScalaZ aren't used in industry jobs, they're more hobbyist things). If you know what a Monad is (like chaining functions like
.thenand.andThenor.mapand.flatMap, like with Futures/Promises) and maybe also what a Monoid is and you know the basic concepts and language features like lambdas/closures, higher order functions (map, filter, foreach, etc.), algebraic data types, composition (and interface inheritance) over class inheritance, recursion, tail recursion (and the tail recursion optimization that exists in some programming languages), powerful switch statements (instead of basic if-else), immutable record/data classes, etc. then you know enough, you don't need to go deep into say category theory or the more intricate parts of the Haskell programming language (which is the epitome of pure functional programming but not really used in industry). If you want to learn functional programming better you can learn Haskell (maybe grab a book on Haskell off Amazon or read Learn You A Haskell for Great Good, the chapters are online at https://learnyouahaskell.com/chapters ) and then transfer some of the stuff you learned from Haskell to other languages, but Haskell itself isn't really used in industry jobs. Even if you learn Haskell nobody will hire you to be a Haskell programmer. If you want to learn the advanced Category Theory stuff for fun with a gentle transition from Object Oriented Programming you can learn Scala and go through the book Functional Programming in Scala, 2nd edition: https://www.amazon.com/dp/1617299588/ . That book will transfer you into the advanced Category Theory concepts gradually (I think one of the authors is a creator of the ScalaZ pure functional programming Scala library). Again, it's not something you need to learn for a real job, it's more an intellectual exercise.p.s. A lot of people mentioned F#. I spent a while looking for functional programming jobs back in 2019 and the only company that ever interviewed me to program in F# was jet.com , it's mentioned at https://www.codemag.com/Article/1611071/Case-Study-Writing-Microservices-with-F . With that little exception, I didn't really see F# being used in industry. If you learn F#, unless you work for jet.com (now https://jet.com/ redirects to its owner Walmart.com), you won't get a job programming in F#. The F# tooling/support with stuff like Microsoft's Visual Studio and ecosystem isn't as good as C#. Most of the time learning it ends up being more an intellectual exercise than something you end up doing for work.
Edit: Also see my response to u/DabbingCorpseWax 's comment at https://www.reddit.com/r/functionalprogramming/s/mToVfnlap5
0
u/DabbingCorpseWax Mar 14 '24 edited Mar 31 '25
library quiet sable marry airport soft capable fragile middle salt
This post was mass deleted and anonymized with Redact
-3
u/snarkuzoid Mar 14 '24
Learn a real language. Not Elixir, one with serious type system like Haskell or Ocaml.
4
u/[deleted] Mar 15 '24
[removed] — view removed comment