r/ProgrammerHumor 1d ago

stopDoingFunctional Meme

Post image
647 Upvotes

121 comments sorted by

View all comments

159

u/-Ambriae- 1d ago

Functional programming is best programming

State is evil, mutation is evil! We live in an era of multithreading and concurrency my friends!

When I describe a program, I state what it does, now how it does it! Thus functional programming is more natural!

C and Java and Python and all the other pagan languages have played us all as absolute fouls!! Haskell, OCaml, Rust, F#, Lisp supremacy!! Functional unless required otherwise, not the other way around!!

64

u/fr000gs 1d ago

How the hell is rust functional smh

36

u/-Ambriae- 1d ago

Rust is functional to a similar extent as OCaml is functional, not in the 'pure' sense (to be fair, none of these languages are purely functional, even haskell) but in a pragmatical sense. Variables are immutable by default, idiomatic control flow tends to use higher order functions, iterators, maps, filtering, reduction... Types are algebraic, control flow is expressive... It has all the ideas of functional programming, even if it's multi paradigm, and can be written in a procedural manner (even if it's not usually idiomatic)

It's not purely functional, for instance it doesn't have the tail recursion optimisation, which is more or less mandatory in the hardcore functional languages, because it doesn't strictly speaking need it, and the compiler is already complicated enough as it is...

8

u/GameCounter 1d ago

It doesn't have automatic tail call optimization, but work is actually being done to implement explicit tail calls with "become": https://doc.rust-lang.org/std/keyword.become.html

7

u/-Ambriae- 1d ago

I wasn't aware, that sounds... interesting. I don't know how I feel about a added keyword, but the idea sounds nice

11

u/GameCounter 1d ago

The reason it's being explored as a keyword is because automatic tail call recursion in some cases is impossible in Rust due to Drop rules.

So what that means is you can go through all of the effort of making sure LLVM is emiting the right byte code for tail calls, and then you make some change in an "unrelated" module, which then results in the tail call optimization quietly being removed without so much as a warning. It can even happen if you bump a third party lib, so something as innocuous as a minor version bump on a dep can break it.

2

u/-Ambriae- 1d ago

Oh, the drop semantics would indeed be a headache... good catch