My journey into functional programming


Everybody knows functional programming requires a shift in the way you reason about your code. And i was told this when i started learning it back in 2017 when i first tried FP using JavaScript.

It was a complete disaster, i couldn’t understand all those concepts from FP, and all those things i saw that people did with FP (like passing functions arround for other high-oder functions) seemed like a high dose of sorcery and madness. So i gave up for a while, because FP was for mad mages from programming, and i felt like although people said i had to abbandon my mindset from imperative programming, no guides would take my by the hand in the process of abandoning it, and how can you step into the unknown without bringing what you already have with you? It’s unconfortable and painful process.

But as time passed, i saw more and more people talking about FP in Javascript, and they were already substituting all kinds of loop code with the famous triad Map, Filter, Reduce. Then i felt upset and angry, tried a bunch of other resources on FP for JS, could already use Map, but it felt weird and unconfortable… it was just like driving a car still is for me today, i can drive one, but if we are talking about it’s engine, i can’t say nothing about it, and if i work with something and i don’t know what’s happening on the background, i get confused, so after some guides and even trying some books, i was still confused.

Then, a guy from the FreeCodeCamp discord channel told me to read How to Design Programs, said there i would learn how to really write a program. Months later in 2018 i took it very seriously, not because of FP, that’s the irony, the reason i started reading HTDP book was because i was coding and designing a front-end page with JS in a modular way, using various files, trying to load animations asynchronously, and i did finish the project i felt i was bad in reasoning how things have to connect the pieces together in software and code. So i decided to dive into HTDP, as the book introduction promissed giving the right piece of knowledge to go forward into this.

After starting to read, i was super excited because i’ve found that the book uses a functional language to teach (a variant of Lisp) so i was eager to find out what was all about.</br>

Three months later i finished the book, i was amazed and i was confident about a lot of FP concepts that now was clear to me, and they were introduced in a really gentle way. The authors literally teached me how to create Map, Filter, Reduce from the scratch without i even knowing (i’ll create a post to teach this with clojure soon), and in the middle of the book they named those functions with the traditional names and my mind exploded righ away. It was too late, i was in love with Lisp and functional programming simplicity and robustness. And for the record, i felt 0% confused while learning FP, because the book has a total step by step approach, it doesn’t even require you know anything about programming before starting.

More importantly, now i knew how to reason about software concepts, how to plan, how to understand the details and how data flows. I cannot emphasize enough that understanding how your data flows in your program and how it’s represented and interpreted is vital. This book completely transformed me as a programmer, best technical book i ever read, and because of that book i came to Clojure, and deeply understood functional programming. It’s a ton of hard work, and HTDP really takes you by the hand, it takes months to complete it (and i haven’t done not even 50% of the exercises), takes patience and perseverance, but it paid off really well, i recommend to everyone who want a guide for FP that REALLY take you by the hand and teach every little tiny thing without rushing anything. I want to talk more about this book but i’ll leave for another post.

I’m not an FP expert, nor i know everything from FP, i’m still a beginner, but being able to code in a functional language after digesting a long technical book feels very rewarding and fun, hope more students are willing to put the effort to learn it, and i saw that a lot of universities are using this book too! If you want to check it out, it’s comepletely free to read on the web here.