Tech News
← Back to articles

The bloat of edge-case first libraries

read original related products more articles

The bloat of edge-case first libraries

This is just some of what I’ve been pondering recently - particularly in terms of how we ended up with such overly-granular dependency trees.

I think we’ve ended up with many libraries in our ecosystem which are edge-case-first, the opposite to what I’d expect. I’ll give a few examples and some thoughts around this, mostly in the hope we can start to trim some of it away.

The problem

I believe a lot of the questionably small libraries hiding in our deep dependency trees are a result of over-engineering for inputs and edge cases we’ve probably never seen.

For example, say we’re building a clamp function:

export function clamp ( value : number , min : number , max : number ): number { return Math . min ( Math . max ( value , min ), max ); }

Pretty simple!

What if someone passes nonsensical ranges? Let’s handle that.

export function clamp ( value : number , min : number , max : number ): number { if ( min > max ) { throw new Error ( ' min must be less than or equal to max ' ); } return Math . min ( Math . max ( value , min ), max ); }

... continue reading