Skip navigation
❌ Avoid deeply nested validations that are hard to read.
0:00 / 1:03

❌ Avoid deeply nested validations that are hard to read.

George Moller

@_georgemoller117K followers

Visit on X
2,135 likesDownloadOriginal post

207,086 views

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

10 Comments

Comments from the original post on X (Twitter)

  • George Moller's profile picture

    @_georgemoller

    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 ↓

    7 likes

  • PATRYK's profile picture

    @__cski

    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.

    166 likes

  • Vlad Tansky's profile picture

    @vltansky

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

    130 likes

  • xavi's profile picture

    @xcanchal

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

    21 likes

  • dcodes 🦀's profile picture

    @dcodesdev

    just use zod

    15 likes

  • Hamilton Greene 🐷🦔's profile picture

    @SIRHAMY

    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.

    11 likes

  • Remus's profile picture

    @remusrisnov

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

    10 likes

  • Proziam's profile picture

    @Proziam

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

    7 likes

  • Ndeye Fatou Diop 🚢 💻 | DEV | 🇸🇳🇫🇷's profile picture

    @_ndeyefatoudiop

    💯 This makes it super hard to read the code

    6 likes

  • Seve's profile picture

    @seveibar

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

    5 likes