18

I've shifted from writing nested ifs to writing early returns. Feels great.

Comments
  • 3
    And you've posted it for review and left half review. You disappeared. @joewilliams007 had a point left.

    Two times env is declared.

    Besides that, nice clean stuff dude
  • 8
    I've shifted from writing nested ifs to writing recursive ifs. Feels wrong.
  • 5
    I would love to be a free spirit like you but sadly my PRs won't be approved if I do that.
  • 3
    one of us, one of us

    there also might be few of us and we might be an endangered species and it's ok to shoot us culturally for some reason 😒
  • 6
    I do early returns religiously. I like it.
  • 3
    @cafecortado what's against early returns?
  • 4
    @retoor Strict coding conventions to whatever project he's pushing to, likely. Some people find that early returns decrease readability... For whatever reason.
  • 3
    @Ranchonyx there's some whole myth stuff about if else blocks regarding cpu cache and shit. Do not count for js I suppose. Sick stuff people do for performance. I worked somewhere where they used tuples instead or arrays in python because of performance. Whaha
  • 4
    @retoor blegh... For me I stand with saying "The earlier a function returns, the better..."
  • 4
    ME TOO!!!!!

    IT FEELS AMAZING
  • 2
    @Ranchonyx but what about taking longer to return to more fully satisfy the logic conditions. Surely the experience of the function is important.
  • 7
    yeah, except it does make traceability slightly more difficult in long/complex methods.

    If I have a nested if-else tree, I try to find a way to either split it into separate methods and "hide" the tree there (x1 if-else per method) OR make an enum-based logic where I pick the processing function from the map (resolution the KEY is often hidden in a dedicated, often times nasty, if-else riddled method).
Add Comment