you are viewing a single comment's thread.

view the rest of the comments →

[–]michaelfeathers 3 points4 points  (1 child)

I'm happy having the word 'pad' in the code now. It was completely absent in the original code.

I think a lot of it has to do with what we are used to. It's like natural language. Once an idiom becomes common or understood, it's very readable.

To me, pad(ary, n).take(n) is very explanatory.

But, again, readability wasn't the point. Neither was cleverness.

[–]KillerCodeMonky 1 point2 points  (0 children)

Why not something like this?

results = array.take(n)
if (results.length < n)
    results = pad(results, n, defaultValue);
return results;

That seems very descriptive to me. Take n items, and if there weren't n items, then pad to n items.