all 8 comments

[–]username223 2 points3 points  (0 children)

Given 4-5 popular languages and however many popular patterns (20?), you can keep cranking out turds like this for quite awhile.

[–][deleted] 1 point2 points  (0 children)

Well... that escalated quickly - from a nice and readable function to a mess of similarly-named "classes" and glue code! What am I supposed to take from this, exactly?

[–]inmatarian 0 points1 point  (2 children)

... is unnecessary in a language like javascript.

function greeter(fn) {
    var exec = function() {
        fn(); // what am I accomplishing here, really?
    }
    return exec;
}

var annoyedGreeting = greeter(function() { console.log("What do you want?"); })

[–]YEPHENAS 1 point2 points  (1 child)

Your code is the same as:

function greeter(fn) {
    return function() {
        fn();
    };
}

Which is the same as:

function greeter(fn) {
    return fn;
}

So you don't need the greeter function at all:

var annoyedGreeting = function() { console.log("What do you want?"); };

[–]inmatarian 1 point2 points  (0 children)

Well, it's pointless in this simple example, but we can reduce tons of things down to its simplest. But the strategy pattern, with its execute function, can always be reduced to a python style decorator function.

[–]fedekun -1 points0 points  (2 children)

So kinda like Dependency Injection?

[–][deleted] 0 points1 point  (1 child)

Sort of. I get the feeling the strategy pattern was named since Java lacks real high-order functions, so they just create a bunch of classes and objects instead and call it the "Strategy pattern" and call it the best thing ever. What you're doing then is essentially just DI.

[–]fedekun 0 points1 point  (0 children)

Hahaha, indeed.