Functional vs object oriented
As a mainly programmer working in mainly in Java, but also using Ext.js for frontend development, most of our code is object-oriented, that is stuff like:
Which, when you code in a normal, oo/imperative style, leads to code like this:
Having an interest in functional programming, and not being able to switch to Scala at my day-time job, I often try to write this in a more functional manner, like:
Which leads me to my problem. Since in a more functional setting, you’d implemented this like:
Which leads to some sort of a break in paradigm, since the former is an example of enriching data with functionality (albeit a simple one in this example) and the latter is an example of functions operating on data, and mixing the two paradigms in one project sort of give me a head ache.
To round this off, here’s another example of this one impelemented in Javascript, which shows the extra boilerplate code needed in a non-functional language, and the other in emacs-lisp which shows how it should be done.