Comment

Comment by JonathonW

If you're going for "each line of code should do exactly one thing", you'd probably prefer that as

    if(foo) {
      if(foo->bar) {
        //whatever
      }
    }
separating out the null check and the actual conditional. More lines of code and more nesting, yes, but, if you're trying to strictly adhere to a one thing/one line principle, you probably don't care.

Short-circuit 'or' is a little harder to avoid (if you specifically want the short-circuit behavior), since you'd have to duplicate the code in the body of the if. But that doesn't come up as often IME.

parent JonathonW 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton