I eventually got to the chapter on functional programming and started it with gusto. Although I was new to the paradigm, it was fun and plain sailing until I got to the section describing the reduce algorithm. Reduce is a popular algorithm in functional programming that allows you to reduce a list of values to a single value.
I tried attempting the exercise on reduce and finally got my program to work. Feeling on top of the world, I checked the author’s code and got two shocks: the author’s code looked ‘nicer’ than mine and worse still, I couldn’t figure out why the code worked.
I refused to concede defeat to some piece of code so I spent the better part of an hour trying to understand why it worked; how it worked and why I couldn’t write such code. I later found out that the only mistake I made was in overlooking the fact that functions can RETURN functions in functional programming. Dumb me? No, I’ve been using OOP and procedural techniques only.
Once I got that, I quickly closed the window, thanked Allaah and went back to my daily tasks and forgot about paradigms, programming and all similar mind-bending stuff. However, my brain felt somewhat nicely stretched – the same way you feel after some tough exercise :D. Victory is sweet.
Next is the map algorithm insha Allah, let’s see who’ll emerge victor.
- learning jQuery (abdulapopoola.wordpress.com)