I was talking to a friend who started doing web development transitioning from game development. I came from a JavaScript background heavily based around Lodash and 'nearly' functional paradigm. I was discussing my interest in more purely functional languages like Haskell and Clojure. Kind of rattled of my distaste for OO programming and how it just doesn't make sense to me, it seems like a lot of fluff and boiler plate when our most common use case is moving data from a form to a data store.
He made a lot of good points that with game development OO makes a ton of sense. I kind of agree. OO works amazingly with game development but with application development I'm really finding the functional paradigm so much more logical.
Functional programming in JS is possible, ramda / wu (others?) make it very easy to get started, of course it is not as great as with functional programming languages, but still, it allows you to do pretty cool stuff, it's like lodash but with the callback moved to the first argument, turning something like this:
var isMultilanguage = function(field) {
return field.multilanguage === true;
};
var isNotMultilanguage = function(field) {
return field.multilanguage !== true;
};
var getMultilanguageFields = function (fields) {
return _.filter(fields, isMultilanguage);
};
var getNonMultilanguageFields = function (fields) {
return _.filter(fields, isNotMultilanguage);
};
into this
var isMultilanguage = R.where({multilanguage: true});
var isNotMultilanguage = R.not(isMultilanguage);
var getMultilanguageFields = R.filter(isMultilanguage);
var getNonMultilanguageFields = R.filter(isNotMultilanguage);
The current stable version of Lo-Dash supports _.curry. In 3.0 Lo-Dash will add support _.rearg, _.ary, & _.curryRight.
Using a combo of them you can easily create auto-curried functions.
var where = _.curry(_.rearg(_.where,1,0));
var isMultilang = where({multilanguage: true});
Comments
I was talking to a friend who started doing web development transitioning from game development. I came from a JavaScript background heavily based around Lodash and 'nearly' functional paradigm. I was discussing my interest in more purely functional languages like Haskell and Clojure. Kind of rattled of my distaste for OO programming and how it just doesn't make sense to me, it seems like a lot of fluff and boiler plate when our most common use case is moving data from a form to a data store.
He made a lot of good points that with game development OO makes a ton of sense. I kind of agree. OO works amazingly with game development but with application development I'm really finding the functional paradigm so much more logical.
Functional programming in JS is possible, ramda / wu (others?) make it very easy to get started, of course it is not as great as with functional programming languages, but still, it allows you to do pretty cool stuff, it's like lodash but with the callback moved to the first argument, turning something like this:
var isMultilanguage = function(field) {
};var isNotMultilanguage = function(field) {
};var getMultilanguageFields = function (fields) {
};var getNonMultilanguageFields = function (fields) {
};into this
var isMultilanguage = R.where({multilanguage: true});
var isNotMultilanguage = R.not(isMultilanguage);
var getMultilanguageFields = R.filter(isMultilanguage);
var getNonMultilanguageFields = R.filter(isNotMultilanguage);
https://github.com/ramda/ramda
https://github.com/fitzgen/wu.js
The current stable version of Lo-Dash supports _.curry. In 3.0 Lo-Dash will add support _.rearg, _.ary, & _.curryRight. Using a combo of them you can easily create auto-curried functions.
You also have those in Underscore / Lo-Dash:
_.filter(fields, {multilanguage: true}) _.where(fields, {multilanguage: false})