DEV Community

Discussion on: ✔||🤢 Commit or Vomit | Switch(true)

Collapse
 
jackmellis profile image
Jack

Since you're returning on each case I wouldn't even bother with elses...

if (useMissedAppointment) {
  return 'nope
}
if (userHasAngularExperience || useHasReactExperience || (userHasVieExperience && userCanStartImmediately)) {
  return 'hire'
}
return 'maybe'
Enter fullscreen mode Exit fullscreen mode

Of course I'd also extract that second conditon into another method, but that's another matter.

Collapse
 
natalia_asteria profile image
Natalia Asteria • Edited

Um, making it a bit inline is better imo.

if (userMissedAppointment) return 'nope';

if (userHasAngularExperience || useHasReactExperience || 
(userHasVieExperience && userCanStartImmediately)) return 'hire';

return 'maybe';
Enter fullscreen mode Exit fullscreen mode

The first line for the second if statement is too long imo. Turned it into two lines.

Collapse
 
jackmellis profile image
Jack • Edited

Personally I prefer all-or-nothing for braces, I really don't like mixing styles. If any of my code has braces, I'd prefer all of my code to have braces. But this is totally off topic and probably a topic for another C/V poll!

Thread Thread
 
jmdejager profile image
🐤🥇 Jasper de Jager

I'll save it for another ✔️||🤢 good idea.
Just have to come up with a good example 😊 and not posting a new one every day is hard but I think this is going to be a weekly recurring item from now on 😎

Thread Thread
 
edave64 profile image
edave64

I personally like to drop the braces IF the condition is small and the statement ends control flow and logically can't have anything after, like return, throw, continue, break, etc.

Collapse
 
jmdejager profile image
🐤🥇 Jasper de Jager • Edited

My preference:

if (userMissedAppointment) return 'nope';

if (
  userHasAngularExperience 
  || useHasReactExperience 
  || (userHasVueExperience && userCanStartImmediately)
) return 'hire';

return 'maybe';
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
natalia_asteria profile image
Natalia Asteria

Oh yeah, I didn't thought that.