Open coolaj86 opened 2 years ago
return
s should convey meaning.
if (x) {
return res.json(x);
}
function runJob() {
return otherWiseUnusedPromisableThing()
}
This axiom was intended to apply at the language level, but it also serves at the framework level. This is bad:
res.json()
if (x) {
res.json(x);
return;
}
async function runJob() {
await otherWiseUnusedPromisableThing()
}
res.json({ success: true });
Correct, Classify, but don't Catch
Preferential order for dealing with errors:
Ex: ENOENT
=> Fs.mkdir(path, { recursive: true })
Ex: mustValidate(userInput)
throws an error with err.status = 400
Don't catch uncorrectable errors locally. Let them bubble up.
Ex: notFatalButShouldBeLogged()
throws an error with err.code = 'E_WARN'
, which is caught and logged by a top-level error handler
Bad Ex:
try {
oops();
} catch(e) {
/* silencing because not sure what to do here */
}
"Perfection is achieved, not when there is nothing more to add, \ but when there is nothing left to take away." - Antoine de Saint-Exupéry
One of the human assets that becomes a real problem when programming is that we can find anything useful - even when it's not for its intended or optimal use. So much so, in fact, that we have an entire area of study dedicated to it - it's called "Art".
Instead, I argue for the RISC (Reduced Instruction Set Computer) principle - less mental burden, fewer edge cases, etc.
Work In Progress
Words that resonate through the halls of the Zen of Python, the Go Proverbs, and other Creeds of Craftsmanship...
Need a more succinct way to say "We did what we always do when there’s a problem without a clear solution: we waited. Waiting gives us more time to add experience and understanding of the problem and also more time to find a good solution." - Toward Go 2
"return await, or await without return"
Omitting the
await
as a shortcut is cute, but likely to lead to bugs when you need to refactor later on:vs