3 ms·
> In other words, people shouldn't make claims that one pattern is objectively more readable than another. Ever. Maybe you haven't seen the sort of code I've s
by cstrahan 2y ago
> In other words, people shouldn't make claims that one pattern is objectively more readable than another. Ever.
Maybe you haven't seen the sort of code I've seen.
Consider this specimen, for example:
// Call a function.
// Function call syntax isn't very visible (only a couple parens tacked onto an identifier);
// this is a major win for readability.
function callFunction(func, ...args) {
return func(...args);
}
// Perform math.
// Math symbols are arcane and confusing, so this makes it much more clear.
// I'm trying to program here, not transmute lead into gold!
function doMath(left, op, right) {
const OPS = {
"less than or equal to": (l, r) => l <= r,
"minus": (l, r) => l - r,
};
// TODO: add support for other operators.
return callFunction(OPS[op], left, right));
}
const MEMO_TABLE = {}
function fibonacci(n) {
if (callFunction(doMath, n, "less than or equal to", 1)) {
const result = n;
// Memoization makes this fibonacci implementation go brrrrrrrrr!
MEMO_TABLE[n] = result;
return result;
} else {
const result = callFunction(fibonacci, callFunction(doMath, n, "minus", 1)) + callFunction(fibonacci, callFunction(doMath, n, "minus", 2));
// Memoization makes this fibonacci implementation go brrrrrrrrr!
MEMO_TABLE[n] = result;
return result;
}
}
Yes, it was an intentional choice to never actually make use of MEMO_TABLE -- this (reproduced from memory) is a submission from an applicant many, many years ago (the actual code was much worse, it was somehow 3 to 4 times as many lines of code).
Compared to:
function fibonacci(n) {
if (n <= 1) {
return n;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
> In other words, people shouldn't make claims that one pattern is objectively more readable than another. Ever.
Taken literally, I can't argue with this. But if you amend that to "people shouldn't make claims that one pattern is objectively more readable than another to competent individuals" (which I suspect is intended to be implied by the original quote), then I'd have to disagree. The choice between functional vs procedural may mostly be subjective, but a convoluted pattern is objectively worse than a non-convoluted one (when the reader is competent).