If you are interested in reading this article in Spanish, check out my blog The Developer's Dungeon
As you probably know if you read my previous article, 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.
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.
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 an unified tool or IDE that could help a clueless guy like me, my most similar finding was Haskell for mac IDE. 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.
As multiple people suggested, I started following Learn you a Haskell for great good 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.
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
- Haskell programming from first principles
- Exercism.io Haskell Track
- Dive Into Haskell
- Category theory book
- A Type of programming
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:
I still cannot write anything to the console, I don't know how to, but that didn't prevented me from starting modelling my own SnakeGame
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 on my short experience:
- Instead of modelling 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
- Instead of writing code specifying what it NEEDS to be done I am writing code representing what things ARE, it feels very strange.
- 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?
- 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 😄