DEV Community

loading...

Discussion on: Functional programming in Go

Collapse
rodiongork profile image
Rodion Gorkovenko

Well, that's very curious idea :)

Go is very far from functional language and paradigm, though it allows operating functions as variables (as C++ do).

However, with the lack of variable matching and tail-recursion, with lack of ternary operator (and really many expressions won't return value) it makes "very poor man's FP".

So honestly I'd say if one wants to practice FP, choose another language. Perhaps Erlang, which, as Go, has messages and easy funny threads out-of-the-box. And use Go for other things.

Go is good language gaining much popularity, worth of learning its concepts. FP is a kind of hype during perhaps last 20 years, as OOP was hype for bit longer. We learn by and by that real tasks don't well map to FP or OOP.

To put it simply, functional programming makes your code more readable, easier to test, and less complex due to the absence of states and mutable data.

Honestly, all this is arguable. In industry I've seen a lot of mess in projects using functional language (e.g. Scala). Main advantage of absence of state and mutability, imho, is that it makes parallel execution and multithreading very easy, as we need no syncrhonization, locks etc. But FP approach sometimes (often) pays in performance for this...

Collapse
jrwren profile image
Jay R. Wren

not to mention lack of either dynamic types or generics. with no generic filter/map/reduce, it makes FP in Go rather terrible. Best to not leave the rails of the idioms of Go.