HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

The eternal dilemma: bar.foo() or foo(bar)?

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
dilemmabarthefooeternal

Problem

I was using foo(bar) as it's adopted for functional programming.

console.log(
    join(
        map(function(row){ return row.join(" "); },
            tablify(
                map(function(text){return align(text},
                    view),
                20))),
    "\n");


Now, with dot operator:

view.map(function(text){return align(text)})
    .tablify(20)
    .map(function(row){return row.join(" ");})
    .join("\n")
    .log();


I guess everyone will agree this reads too much better, and the only cost is that you have to modify the native types prototype. So, which?

Solution

I think that the first variant can look nice, too, if you change the way you format the code and you always use the function as the last argument:

log(map(tablify(map(view, function(text) {
  return align(text)
}), 20), function(row) {
  return row.join(" ")
}).join("\n"))


Edit: Or if you really like indent:

log(map(tablify(map(view,
                    function(text) { return align(text) }
                ),
                20
        ),
        function(row) { return row.join(" ") }
    ).join("\n")
)

Code Snippets

log(map(tablify(map(view, function(text) {
  return align(text)
}), 20), function(row) {
  return row.join(" ")
}).join("\n"))
log(map(tablify(map(view,
                    function(text) { return align(text) }
                ),
                20
        ),
        function(row) { return row.join(" ") }
    ).join("\n")
)

Context

StackExchange Code Review Q#24526, answer score: 2

Revisions (0)

No revisions yet.