Skip to content

Instantly share code, notes, and snippets.

View jtwebb's full-sized avatar

John Webb jtwebb

View GitHub Profile

Some Musings on Guard Clauses and Fault Tolerance

“Or: How I Learned to Stop Worrying and Love the Exception”

Background

I used to work at a healthcare technology company that was headed on the tech side by a database nut. The data model was both sprawling and very normalized (by that, I mean gnarly). We worked mainly in the exciting realm of medical billing and patient demographic data – particularly involving data with errors and omissions needing correction. Concordantly (😏), a large proportion of the relationships between tables were represented with nullable foreign keys.

Safe, Deeply-nested Logic

I often found myself working on code similar to this contrived simplification …

@tombigel
tombigel / utils.ts
Last active August 8, 2023 07:00
Helpful Javascript functions I use frequently, mainly vanilla alternatives to lodash etc.
/*!
* Deep merge two or more objects together.
* (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com
* @param {Object} objects The objects to merge together
* @returns {Object} Merged values of defaults and options
*/
export function deepMerge(...args: any[]) {
// Setup merged object
const newObj: Record<string, any> = {};