One of the characteristics of functional programming is as follows:
You’re describing the result you want rather than explicitly specifying the steps required to get there.
I found this quote at https://realpython.com/python-functional-programming/.
I don't really understand what is the meaning of this. Functional Programs still have to define steps to calculate something, there is no magic.
For example, a quicksort in Haskell looks something like this:
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
I don't really understand where the "you're describing the result" part is there. In imperative programming language I'd do pretty much the same thing. The only difference is that probably I wouldn't have a one-liner like [a | a <- xs, a <= x]
, I'd have to do some loop. However, it's just syntax sugar, normally I'd create my own method/function that does exactly the same thing as [a | a <- xs, a <= x]
. So, I don't consider that syntax to be some breakthrough, because it could some as a library in any other language.
Could you help me to understand the meaning of the quote in the title of this post?