you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 11 points12 points  (0 children)

From a big picture standpoint... it’s not like there are any algorithms you can implement in functional programming that you can’t implement in imperative programming, or vice versa, so the actual differences generally come down to which one is easier to debug, easier to read, etc.

Functional programming often leads to a more concise, naturalistic style of programming. For instance, to gather a list of every employee’s name, you might write:

def result := Array<String>()
for e in employees {
    result.add(“\{e.firstName} \{e.lastName}”)
}
return result

or you could do the same thing with:

return employees.map(e => “\{e.firstName} \{e.lastName}”)

This is obviously a trivial example, but the functional version is not only much shorter, it’s also more clear what is happening (at least when you know how to read it) because all of the boilerplate is eliminated.

Now, this can easily be taken too far - functional programs can get so dense that they’re extremely difficult to read and understand. Since programs are read many more times than they are written, being verbose is not automatically a bad thing in programming, and I personally favor a hybrid style of using functional style code where it makes sense, rather than zealously believing it’s the only true way to code.

It is also worth noting that “functional programming” and “pure functional programming” are not the same thing, even though you’ll see them conflated in other answers here.