this post was submitted on 13 Aug 2024
30 points (100.0% liked)
Rust
5999 readers
7 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Minor nit: Kotlin is decidedly not a functional language.
Design patterns in OOP exist purely to solve the problems created by OOP itself. If you have a language with proper ADTs and higher order functions, the need for traditional design patterns disappear since the problems they solve are first-class features baked into the language.
The first-class replacement for the Strategy pattern (and many other patterns such as the Visitor pattern) is sum types (called enums in Rust).
Truth has been spoken.
Except that Kotlin is functional (just like Rust, C++, Visual Basic, JavaScript,...). It is, however, not Pure Functional (like Haskell or Lean4 would be - if you haven't checked out Lean4, I can recommend it, great fun).
(Sauce: https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Functional_languages)
That list also counts Java and C# as "functional languages". I wouldn't take it too seriously. Ocaml, Scala, F#, etc. are impure functional languages. Kotlin absolutely is not. Having a couple of features you might find in functional languages does not make a language functional. Kotlin is still very much an OOP-based language. It's basically a somewhat nicer Java.
I know, from a mathematics standpoint it does not make sense, but from how the term is used nowadays in programming it does: Those languages allow to compose functions, pass functions as parameters, return functions, etc.
A language is not functional just because it supports higher order functions. Technically C even supports them (even though the ergonomics and safety of them are terrible). Would you call C a functional programming language? Obviously not. Rust is also not a functional language, even though it comes closer than most OO/imperative languages.
Kotlin and plenty of other OO languages have borrowed some ideas from functional languages in recent years because those ideas are useful. That doesn't make them functional languages. If Kotlin were a functional language, then it wouldn't need libraries like arrow to try to make doing FP in Kotlin even (kind of) possible.
Hallmarks of FP (beyond higher-order functions), in no particular order:
There are some minor exceptions, such as Clojure lacking pattern matching, but on the whole functional languages generally fit these descriptions.
Points that I would gladly agree upon - but it seems the Wikipedia authors don't.
I am not knowledgeable enough to draw a definite line what counts as functional and what doesn't - so I chose to go with whatever Wikipedia says... Even though I dislike it.