Functional Programming in Go
bitfieldconsulting.com
bitfieldconsulting.com
It brings Java libraries like vavr to mind. The concept has appeal if you appreciate the aesthetics of functional programming but your codebase will be filled with places where you have to convert between the sexy functional style and the boring shit in order to get anything done.
It's better to just roll with the language and stick to where it excels. It may not be as easy on the eyes and it may also be boring to write, but a lot less can go wrong with it.
I find the attitude tiresome. Sure, in an abstract sense, there’s “more” to FP than these common abstractions. But there’s also less: FP is ultimately about acting on values. The “functional” part is an acknowledgment that a “function”, in its mathematical sense, is the common abstraction which achieves that. Map/filter/reduce are no more fundamental to that than any of the typical academic concepts often found in ML-family languages. Nor, as a detractor on Twitter suggested to me recently, are persistent data structures essential. Values are the essential concept, and all else that FP offers are in service of that concept.
You can apply the same principles in nearly any language. You may need to build up your own implementation of some common abstractions to benefit from them. You may find certain patterns inherently awkward due to language semantics, or sometimes just syntax. Ultimately it’s still rewarding, from the perspective that one will be using said non-FP-paradigm language anyway. Because working with values is its own reward. And it’s incredibly rewarding, even if limited.
I don’t think it does anyone any good to gatekeep that on the basis that the compromise… is a compromise. Sure, it’s worth pointing out that there are limited benefits. But none, in my experience, so limited that they negate the benefit entirely.
It was insanely slow and unintrospectable, to get elixir syntax for ruby they had to abuse blocks horribly, refactoring was decent for already existing components but as an org they had the slowest ruby "new feature" development I've ever seen in 20 years.
Don't throw away all your debugging and IDE tools just to shoehorn a different language paradigm into your existing codebase, if you can prove to me that you have put co-commiserate effort into the tooling and can actually demonstrate this fact practically then you are good but probably still wasting time and should switch to elixir/f# or whatever.
This group hired me because I was the only outside senior level person that was a rubyist and an elixir guy with a lot of FP work in the data space willing to give them a shot (fp is good, it's a good tool but not a panacea, fp is borderline an academic cargo cult nerd snipe in how people proselytize and get into it imo) and I was at a career point where I was doing a lot of exploratory stuff so I found them intriguing since they did have a real product in prod.
In my interview process, I didn't vet their actual dev process nearly enough, total waste of time for people who want to do product development with any velocity.
- Ergonomics weren't the greatest when working with monads such as options and results. I think pattern matching is needed here, but concepts like those go against Go's core design philosophy.
- I suspect there are several cases where runtime performance is an issue, but admittedly did not investigate this.
- Perhaps most importantly, it deviates from the way most people read and write Go, and less importantly, LLMs struggle too.
Because of these reasons, I came to the conclusion that the advantages were not worth the trade-offs.
Perhaps somebody will create a garbage-collected Rust-like language in the future and bridge the gap between the two languages.
F# :)
Gleam is pretty nice in that regard I think, I can see some parallels with Go in terms of simplicity and Rust in terms of basic syntax, it does currently lack a native target that produces a Go-like single binary though.
I’m a fan of Go and FP and would love to see someone bridge other FP aspects like monads, in a way that feels natural in Go.
Was just talking about this during a 1:1 with a colleague of mine today. It's remarkable that language developers have set out to do clean sheet designs (golang, rust) and somehow managed to settle on gross syntax. If I were desigining a language today it would look and feel like Python without any of the performance hurdles.
You are talking of your opinion as some kind of facts. What you call gross syntax is good enough for people to write enormous amount of useful software that millions and millions use daily. The same can't be said for Clojure.
For example raku (and perl before it) has very good support with map/grep/closures, etc.
https://rakujourney.wordpress.com/2024/10/12/raku-burritos/
Says…
And let’s end with a quote (sadly I did not record the originator)…
I think i just expressed my thought in a wrong way, haha. I am a functional freak, and the first thing i did was check out Raku’s functional patterns. I was amazed. Raku can be extremely functional, but in my opinion language can be called functional when there’s no other way other than functional for the most part. Raku has great functional support, but the language doesn’t force you into anything, you can do basically anything! A sandbox language, and i am loving it.
anon
It doesn't feel like Go, really, but there is still a place for high level testing like that. Personally, I prefer it for integration testing and other situations where you might be asserting on multiple steps of functionality as part of a wider piece (like transactional business logic).