Loading video...

Video Failed to Load

Go Home

❌ Avoid deeply nested validations that are hard to read. ✅ Instead use invariants.

206,841 views • 1 year ago •via X (Twitter)

10 Comments

George Moller's profile picture
George Moller1 year ago

I've been working professionally with React and JavaScript for more than 8 years and I compiled all my knowledge into 100+ infographics and 70+ video tutorials just like this one. Check them out ↓

PATRYK's profile picture
PATRYK1 year ago

Don’t follow this advice. It makes your code less readable, it confuses other developers and your IDE. This level of abstraction is not helping anybody. Just use early return.

Vlad Tansky's profile picture
Vlad Tansky1 year ago

Nice, but wouldn’t it be easier to read code with if(!condition) throw new Error(“some message”) Instead of creating abstraction?

xavi's profile picture
xavi1 year ago

Just use fail fast/ early return and you’ll avoid that level of abstraction.

dcodes 🦀's profile picture
dcodes 🦀1 year ago

just use zod

Hamilton Greene 🐷🦔's profile picture
Hamilton Greene 🐷🦔1 year ago

I don't like this - you're hiding important control flow inside deeply nested functions. The caller must now know that implicitly your functions use exception control flow and throw on certain conditions (also hidden). Guards (if not x return) are usually better.

Remus's profile picture
Remus1 year ago

Dude an "any" wrapper function? That's scares the shit out of me

Proziam's profile picture
Proziam1 year ago

I have to know, what are you using for the animations and graphics? Looks clean

Ndeye Fatou Diop 🚢 💻 | DEV | 🇸🇳🇫🇷's profile picture
Ndeye Fatou Diop 🚢 💻 | DEV | 🇸🇳🇫🇷1 year ago

💯 This makes it super hard to read the code

Seve's profile picture
Seve1 year ago

"early bail" or "early return" is far better terminology

Related Videos