News for hackers. Stuff that matters.
Re:Programming Patterns I Like by foota on Saturday June 29, 2019 @03:47AM (#20311350)
Personally, I'd prefer to go with early return, I think. Depending on what the conditions mean semantically.

It would be:

  if (conditionA && conditionB) {
    return "A & B"
  }

  if (conditionA) {
    return "A" 
  } else {
    return "Not A"
  }
  
  return "neither A nor B"
I think this comes from a general dislike of more than one else on an if and a dislike of nesting.

There are no comments on this comment yet.