Learning functional programming with javascript

“A monad is a monoid in the category of endofunctors” - This little sentence is somewhat of a running joke among selftaught programmers trying to get the hang of functional programming.

Imperative programming is relatively easy to pick up for muggles in the field of computer science. Languages like python and php have a low barrier-to-entry - not requiring a solid background in computer science or mathematics - a basic grasp of english and math is all that’s needed.

Functional programming, by contrast, isn’t. It’s terse and not very intuitive unless you’re familiar with certain mathematical concepts. There is no “pick up this book and you’re good to go” language or ecosystem.

Learning by applying

Analyzing and cutting a problem into pieces, dissecting those pieces further into the smallest useful part and understanding how those small pieces fit together is the right start to gaining a profound understanding of any topic.

Taking those parts, reconfiguring them and putting them together again - all the while reasoning about the way they should interact and what they should digest or output - that’s how you gain a full understanding of how to apply what you’ve learnt into practice.

I learned very early the difference between knowing the naming of something, 
and knowing something. - Richard Feynman

Imperative, procedural programming is simple to grasp. Most languages seem to follow some form of english idiom. The atomic parts are akin to language constructs: If this, then that. Increment this counter. Loop until this counter reaches that.

The atomic parts of functional programming, however, seem deeply rooted in lambda calculus and category theory. This makes generating a mental model that we can weave into the tapestry of our mental fabric a lot more difficult. The concepts have scarcely any correlations to previously acquired knowledge.

What you would ideally want is some form or model of reasoning which can be woven into the existing laticework of models of understanding gained by using and understanding imperative languages.

Along comes javascript

Widely adopted and generally available. If need be, you can just open your browser’s console to test a concept.

But what I like most, is the direct availability of material that takes me - step by step - through programming concepts without having to rely on category theory, or branch off into abstract mathematics for which I have no preexisting context or mental models.

The works I’m talking about?

Functional Light JS - by Kyle Simpson / getify

Professor Frisby’s Mostly Adequate Guide to Functional Programming - by Brian Lonsdorf / DrBoolean

These works build upon knowledge of imperative programming - and show you how functional programming can make things easier, faster or more maintainable by doing. There is often an actual comparison between procedural and functional code which you can reason about.

And that’s what I really love about these books. If you can reason about code in the two different ways and understand the advantages and disadvantages of the two styles, you’re well on your way to truly understanding the concepts they envelop.

(P.S. I’ll probably still pick up basic category theory, as I just love math - but sometimes shortcuts are the way to go if you just want to get up and going with certain concepts without needing to know how they work)