DEV Community

Discussion on: Where do you prefer your conditionals – inside or outside?

Collapse
 
rvisharma profile image
Ravi Sharma • Edited

Interesting!
Your approach would actually eliminate the cons that i mentioned. Thanks for book mention, will check it out.
Based on your comments it can look something like this.

function run() {
  if (isMobile) {
    runMobileFlow();
  } else {
    runWebFlow();
  }
}

function runMobileFlow() {
  notifyInApp();
  log();
}

// only to be called in Mobile
function notifyInApp() {}

function runWebFlow() {
  sendEmail();
  log();
}

// only to be called for web
function sendEmail() {}

function log() {
  console.log("common logging");
}

// Start
run();

Enter fullscreen mode Exit fullscreen mode