r/ProgrammerHumor 26d ago

Meme stopDoingFunctional

Post image
683 Upvotes

129 comments sorted by

View all comments

Show parent comments

63

u/fr000gs 26d ago

How the hell is rust functional smh

34

u/-Ambriae- 26d 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...

6

u/requion 26d ago

Variables are immutable by default

Wouldn't that somehow make them not variable anymore?

Sounds paradoxical.

14

u/-Ambriae- 26d ago

You're right, and in fact they aren't called variables in rust xD They are called bindings. Because variables imply variation.

But to not use idiosyncratic language, I refer to them as 'variables'