I face this dilemma as well as I like to avoid excessive branching if possible. However, If you follow the recommendations from Clean Code amazon.com/Clean-Code-Handbook-Sof... you should limit functions to do one thing ONLY and do it very well. For your example above, my advice would be to have one function for the mobile case, a different one for native, and have the name of the function clearly state that. Otherwise the outcome of doIt() is not clear. It can do something or not.
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.
functionrun(){if(isMobile){runMobileFlow();}else{runWebFlow();}}functionrunMobileFlow(){notifyInApp();log();}// only to be called in MobilefunctionnotifyInApp(){}functionrunWebFlow(){sendEmail();log();}// only to be called for webfunctionsendEmail(){}functionlog(){console.log("common logging");}// Startrun();
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I face this dilemma as well as I like to avoid excessive branching if possible. However, If you follow the recommendations from Clean Code amazon.com/Clean-Code-Handbook-Sof... you should limit functions to do one thing ONLY and do it very well. For your example above, my advice would be to have one function for the mobile case, a different one for native, and have the name of the function clearly state that. Otherwise the outcome of doIt() is not clear. It can do something or not.
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.