this post was submitted on 22 Jun 2023
27 points (100.0% liked)

Functional Programming

1398 readers
1 users here now

founded 1 year ago
MODERATORS
 

Hello fellow FP-Lemmyites. I'd love to hear stories about what got you interested in FP originally, and how you learned.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 1 year ago (5 children)

I was learning Java 6 in highschool. One day my brain wrinkled and I asked the teacher a big question:

"Why can't methods be more like variables? I want to try, like, making an array of methods out of it"

My teacher, bless his heart, replied:

"I'm just a P.E. teacher filling in electives because the county can't afford to hire anyone with a computer science degree, but go ahead and install whatever you want if you feel like experimenting"

So I stumbled around Google for a while playing with phrases like "passing methods without anonymous inner classes" and "public final methods" until I eventually stumbled across a bunch of blog posts by this guy called Martin Odersky. That led me directly into dropping Java and picking up Scala, the JVM language he designed.

Scala basically blew my world open. I discovered the beauty of first-class functions, immutability, currying, and pattern matching. Unfortunately, Scala was sort of peaking at the the time, so I eventually had to pack up and learn other languages. I experimented with Haskel (too hardcore for me!), Elixir (good but tiny ecosystem), and Groovy (cool, but unfocused). I always ended up returning to lame languages like JS (meh...), Python (ugh...), and Lua (ugh!!) because that's where the projects that most interested me were happening.

These days I mostly work in JS professionally. It's not ideal (hungrily eyes tc39/proposal-pattern-matching & tc39/proposal-pipeline-operator)... but my FP background still has a lot of applicability in JS-land. I frequently receive compliments on my code and I attribute a large part of that to the lessons and discipline which FP has taught me.

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (4 children)

Quick little followup question to my own comment: I'm considering picking up Rust because I'm a big fan of what they're doing with immutables and pattern matching. Are there any Rustaceans on this community? What do you think of it as far as the FP experience goes?

[–] grayrest 3 points 1 year ago (1 children)

Rust is not a FP language. It's an imperative language with restricted state and a few FP constructs included.

To me what makes a language FP is the mindset and that boils down to deciding to fold instead of loop and you lean to closure captures instead of declaring variables. Both sides of these are basically equivalent but having a function as the big hammer you use to nail everything together is what makes it functional programming instead of X programming with some functional ideas carried over.

When people structure a request like this they're generally after a way to really get into the ideas and the best way to do that is to use a language that's built around FP ideas. I personally recommend Clojure and OCaml. If you'd like to do Scheme via the Wizard book then that's fine as well. I don't really like the pure functional languages (Haskell and friends) because I think that state is a useful thing in small doses and don't like jumping through the extra hoops to get at it.

[–] philm 1 points 1 year ago

Rust is not a purely FP language, indeed, but I think it's absolutely fine to program almost only FP in it, then you have almost no issues with the borrow-checker. Though since it's a multiparadigm, I obviously decide for each problem the best approach which is not always FP... Often it's just simpler to read imperative code. But I almost always default to fold in Rust anyways.

Though e.g. currying and the likes is certainly more fun in real FP languages (like Haskell).

The more experience I get in all these languages the more I think Rust has found the "perfect" balance of paradigms and readability (well at least to date). But this is obviously also a matter of personal preference... I'm really looking forward that all the boilerplate is reduced when programming with a lot of generic trait-bounds (i.e. more inference where it makes sense), I think this is still an area where Rust could improve (also compile times, like incremental trait solving).

load more comments (2 replies)
load more comments (2 replies)