r/functionalprogramming • u/kichiDsimp • Mar 03 '25
Question Can I stick with JS/TS
Hey fp-enjoyers.
I really want to do functional programming in a functional langauge. I learn fp from Haskell, arguably it was the most mind bending experience for me. But, when I tried building stuff with it (for example a TUI app) it was so tough, not enough community support along with not good documentation. (Please don't try to justify it)
I went on a ride with Clojure. I am skeptical about it. Shall I really spend my 6 months in it ? Or shall I just learn FP in JS/TS and implement stuff there and built it ? I have come across a book Grokking Simplicity. I don't know what's the depth and breath of it, but it seems readable . I have seen quite good GitHub repos with FP in JS. Turns out there is a SICP version also of JS.
Basically I want to build stuff, while writing beautiful, readable and enjoyable code. I have a image that Clojure is like this or maybe not ?
Please share your opinions !
20
u/TestDrivenMayhem Mar 03 '25
https://effect.website/
4
u/RomanaOswin Mar 03 '25
If you want to lean into FP and still have a strong ecosystem, IMO, Rust is probably the best option, especially if you want to create a TUI. The lifetime concept will be hard at first, but if you're able to get your head around Haskell, it's not that bad. It's also not strictly FP, but it has really strong support for FP as a first class paradigm.
Clojure/Scala, Elixir, and F# are all good and have a lot to offer, but they're tied to the JVM, BEAM, and CLR respectively. This could be good or bad depending on your use case. For a TUI, it's probably not ideal; for a web app or network service, it might be great.
OCaml/Reason is another option. Excellent language, but if ecosystem is your primary concern, you'll probably end up in the same situation as Haskell. OCaml has libraries for most purposes, but they have nowhere near the momentum or qualify of documentation you're used to with JS. Reason and Rescript can also compile to JS, but interop with JS is more effort and it kind of makes it feel like you're not really participating in your own ecosystem.
My advice would just be to use Rust unless one of the three major VMs are appropriate for your use case. Rust will feel like more work to start with, but once you get your head around it, you can create very expressive and readable code.
2
u/delventhalz Mar 03 '25
JS gets a lot of guff, but it is arguably the most mainstream most functional language there is. Moreover, people actually hire for it, and functional patterns are pretty popular in the JS community. Overall, it’s not a terrible choice, but it certainly follows a pretty loose version of FP, so you may want to consider some stricter options.
Clojure compiles both to the JVM and JS, so right away it is compatible with plenty of mainstream toolchains. Going from a C-like syntax to a Lisp is a bit of a learning curve, but I’ve worked in Clojure a bit, and it quickly became of my favorite languages. There is also some hiring for it. Loved Clojure for the Brave and True as a way to learn.
Other options might include Scala (compiles to JVM, probably the most widely used non-JS functional language), Elm, Elixir, PureScript, or F#.
4
u/biskitpagla Mar 03 '25
SICP JS version has some of the most cursed JS code I've ever seen. I don't quite understand your concern. If you want FP because you enjoy it, you're not going to have your needs met in JS. If you want FP because of the benefits, you're also obviously not getting it from the JS ecosystem any more than any other mainstream ecosystem.
If you're more interested in the latter case, learning a niche library that implements some pseudo functional lang on top of JS and bleeds into all your code requiring you to wrap third party code and so on is kinda sorta against the very reason you will have picked JS imo. Coming back to SICP, there's a 'comparison' version that has all the text and code (both JS and scheme) from all the versions in the same book. For TUIs, Rust and even Go have some decent libraries that try to employ functional architecture.
11
u/circleglyph Mar 03 '25
If you want to actually get stuff done and get great support along the way, and you're not addicted to the brutal clarity that can be achieved in a functional-only language (as I am), then JS is the best FP language out there. But if FP is clicking for you, you'll still want to keep up with what the purists are doing in the research FPs. If you expect that the repetitive strain of using a lower-quality language design will wear you down, then use the best FP language you can find for everything you can.
The canonical library for tui in Haskell seems to be brick and the documentation looks gorgeous! Maybe uniquely for Haskell it even has a user guide, so I am a bit undecided how to shape my opinions to your question. If you didn't use brick then I understand - library discovery and working out library quality is hard in a small community. If you did but the problems were upstream library support than yes, active fp code and coders are not anly a small community but tiny. This is often fatal and a very good reason to stick with the majors for any particular project.
In terms of juggling, if something is really important or I expect it to still be useful in 10 years, I code it in Haskell - if only to make sure I fully cover the problem and get it right. I redo it in JS if support is lacking in the problem domain of the project, and have my ways and boiler-plate to refactor the initial work.
If it's less important, I will start in JS, but I would tend to at least write out the types if I hit major snags.
Lack of docs/community/support (as you put it) gave me the sads for a while, but it gets a lot easier the more experience you have. You toughen up to no doc libraries because you still have the joy of using a high-quality language. You get better at library discovery, more discerning of library quality (there are maybe 20 Haskell libraries I would recommend after 12 years of coding with it), and unafraid to kick it all to the curb because FP in JS is pretty good too.
Also, if you have a fundamental issue like which language should I use, nothing beats hopping onto leetcode or whatever and doing a set of problems in several languages. When I first started, I pretty quickly concluded that FP is as much a state of mind, a style of thinking, as it is a category of language, and (for me) I found I could switch between a few languages without too much friction, but struggled with OOP basics.
5
u/no-vid Mar 03 '25
Elm and ReasonML have great community, documentation and tooling.
4
u/imihnevich Mar 03 '25
To be honest Grokking Simplicity is quite simplistic, there's much more to FP than what it can offer. I would suggest learning some FP-first language (it was and is Haskell for me) even if you come back to JS after that. The way you write JS is just gonna be different
2
u/chamomile-crumbs Mar 04 '25
I will say that it’s a lot of fun to learn clojure. I mostly use typescript for work and little random projects, but clojure is just super cool and fun. So it’s definitely worth messing around witu
2
u/sminnee Mar 07 '25
Give ReScript a go and see what you think. It’s OCaml under the hood, but designed to be more easily understood by JS devs. A few others have mentioned ReasonML - these were once the same project but have diverged a few years back.
https://rescript-lang.org
0
u/Positive_Total_4414 Mar 03 '25 edited Mar 03 '25
ReasonML is there, which is basically OCaml, which in turn also, interestingly, has its own transpiler to JS. Must be a to-go for FP of the JS ecosystem. Has a great support in VSCode.
TypeScript is ok, but I wouldn't say it's a FP language.
There's also PureScript, but I don't know what is its status.
There's also F# that has its own way of working with JS, and it also has FuncUI, which is a wrapper for AvaloniaUI, so it covers a lot.
JS itself is not a functional language, it's a chaos language. I wouldn't recommend actually using the language itself.
Also, I wouldn't say that "sticking" to the JS ecosystem needs to be a life commitment. Use it when appropriate, but prefer real programming instead when you can.
0
u/[deleted] Mar 03 '25
[deleted] — view deleted comment
4
u/[deleted] Mar 03 '25
[removed] — view removed comment