Let's go on an adventure, a functional one.
Tags: beginners, codenewbie, webdev, career
Published: 2020-01-06 19:34:41

If you are interested in reading this article in Spanish, check out my blog [The Developer's Dungeon](https://www.patferraggi.dev/blog/2020/jan/aventura-funcional/)

As you probably know if you read my previous [article](https://dev.to/patferraggi/planning-my-career-development-for-2020-4okc), I am not a functional programmer, far from that. My real-world experience lies all behind the courting of Object Oriented Development. Well no more, I decided that I wanted to check what it is all the cool kids are talking about, see for myself if the benefits are real or just rumors.

This is all easier said and done as I would soon found out.

---

There are so many flavors of functional programming that I did not know which one to pick. I first read [Structure and Interpretation of Computer programs](https://web.mit.edu/alexmv/6.037/sicp.pdf) and I really liked the Lisp type syntax, so Clojure was brought to my attention. I am also a C# developer so naturally, F# was mentioned multiple times... and after I read [Mostly adequate guide to functional programming](https://mostly-adequate.gitbooks.io/mostly-adequate-guide/) the idea that JavaScript could be enough for this journey was on the table too.

In the end, I picked the 'Hard Road', I wanted someone that would hit me in the face if I even thought about doing anything in an Object Oriented or Structured way, so that is how the holy grail of functional programming appeared.

## Haskell

This is the first time I am learning anything remotely related to functional programming, the first time learning a language that has no C styled syntax and also the first time I don't have a real-world project I can jump in to get dirty immediately.

So the beginning was not easy, I searched forums and blog posts and it seemed like there was not a unified tool or IDE that could help a clueless guy like me, my most similar finding was [Haskell for mac IDE](http://haskellformac.com/). After spending half a day installing things that would not work on VSCode I decided to put out my wallet and just buy the damm thing.

![Haskell](https://thepracticaldev.s3.amazonaws.com/i/72lqto1aiijvmcwbr5z5.jpg)

As multiple people suggested, I started following [Learn you a Haskell for great good](http://learnyouahaskell.com/) and to be honest, I haven't had such a hard time reading a book and trying to learn something new in ages, although I understand the basic concepts about functional programming and pure functions, referential transparency and shit, every time I want to solve something on my own without looking at the book my mind gets blank.

I don't quit easy but I was shocked when I realized how slow I was making progress, so slow that I had a meltdown on twitter asking others if this was normal or if I was doing something wrong.

![Meltdown](https://thepracticaldev.s3.amazonaws.com/i/z81liau0yfay0rhjtlz6.png)

After struggling another extra day with the IDE and tooling -actually 2 IDEs, Intellij with the Haskell plugin for "Real Development" and Haskell For mac for testing and using the REPL- I started reading the comments I got on twitter and discovered some really nice extra resources:

- [Zero Bullshit Haskell](https://github.com/alpacaaa/zero-bullshit-haskell)
- [Haskell programming from first principles] (https://haskellbook.com/)
- [Exercism.io Haskell Track](https://exercism.io/tracks/haskell)
- [Dive Into Haskell](https://github.com/politrons/Dive_into_Haskell)
- [Category theory book](https://bartoszmilewski.com/)
- [A Type of programming](https://atypeofprogramming.com/)

I also received some encouraging words that made me realize the way I was feeling was perfectly normal. That is when it hit me: I haven't felt this way since I was starting to learn programming, indeed learning Haskell and functional programming is like learning everything all over again.

No variable assignation, no loops, no mutable state, no classes or objects, recursion? hello world?

Slowly I am starting to write my own functions: 

![MyFunctions](https://thepracticaldev.s3.amazonaws.com/i/u2uzndrny114btn7baj6.png)

I still cannot write anything to the console, I don't know how to, but that didn't prevent me from starting modeling my own [SnakeGame](https://elgoog.im/snake/)

![SnakeGame Implementation](https://thepracticaldev.s3.amazonaws.com/i/nsbpocena561oan3zbj1.png)

---

I know what you are thinking, is there anything positive you can say to me? You are not selling me this adventure of yours dude.

I can only tell you what I noticed in my short experience:

1. Instead of modeling complicated classes representing domain objects with methods that would represent behavior and considering encapsulation, the code I produced so far naturally moves towards very very very small functions and because of the small composable functions it seems very hard to actually break the [Single Responsibility Principle]
(https://en.wikipedia.org/wiki/Single_responsibility_principle)
2. Instead of writing code specifying what it NEEDS to be done I am writing code representing what things ARE, it feels very strange.
3. Most of the design patterns I often use are kind of useless, why would I create a factory if I can just return a function?, why would I implement a strategy if I can just pass a function as implementation?
4. Haskell's type system is much more clever than others I have encountered, it usually knows what I want to do and gets out of the way if the functions actually make sense. Because of this, it is also possible to omit certain syntax because Haskell already knows what you mean.

I have to say that it is very challenging, but it is also fascinating, I truly think that this adventure can lead me to a place I would never want to come back from.

Unless I get eaten by a dragon I will be writing often to share what I have learned in this journey :smile: