Skip to content

Instantly share code, notes, and snippets.

@BalmungSan
Last active December 31, 2022 04:54
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BalmungSan/bdb163a080af54d3713e9e7c4a37ff51 to your computer and use it in GitHub Desktop.
Save BalmungSan/bdb163a080af54d3713e9e7c4a37ff51 to your computer and use it in GitHub Desktop.
Why Functional Programming?

Why Functional Programming?

Probably not the most poetic nor academic or well written phrase, but let me express in plain English why I end up choosing Functional Programming.

Over my time coding (which I have to clarify that has been short) I have learned two important things about code.
(mostly from the experience of many more veteran colleagues)

  1. The best line of code is the one that is not written. Why? Because, every single line of code that you write is instant technical debt. No matter, how well done it is, how well designed it was, how much of 1000x programmer you are, all the code is debt. All the code will become obsolete at some point in time, all the code has to be refactored.
    And that is because the world changes over time, and so does your program.

Given the previous, then you can conclude the next one.

  1. All code is read more times than it is written. A functionality is written once, but probably will be changed many times in the future. Even if it won't be changed, it will have to be understood by someone else in the future (someone may be your future you).

Thus, why FP?
Well, because the abstractions provided by FP gives me:

  • Shorter code, because it focus on the task at hand and hides away the process (declarative vs imperative).
  • Reusable code, because you are using very general abstractions which can be applied to many domains.
  • More understandable code, if you know those abstractions then everything follows naturally.
  • More correct code, because those are well studied and proven abstractions; also the type system can prove many things for you even before running your tests.

And all this is based on the two fundamental principles of FP:

  • Composition.
  • Referential transparency ==> local reasoning.

Of course, the same has been said of all the other programming paradigms / techniques.
I just think FP is the next step, which brings us to a higher level of abstraction.

Also, it has to be noted that FP isn't the saint grail on its own. (that's Graal 😜)
You can write horrible and unmaintainable FP code, and beautiful a super duper clean imperative code.
I have just found that, for me, it is easier to write good FP code than good imperative code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment