Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use flags as function parameters #235

Open
kanalasumant opened this issue Dec 4, 2017 · 2 comments
Open

Don't use flags as function parameters #235

kanalasumant opened this issue Dec 4, 2017 · 2 comments

Comments

@kanalasumant
Copy link

@kanalasumant kanalasumant commented Dec 4, 2017

Thanks for this wonderful curation of clean coding practices. I don't have so much as an issue but I'm unable to wrap my head around this rule, as to how does one split the function into two functions without actually knowing the value of temp which can be only be known with an if statement. This seems like I should use polymorphism but my question is about this particular issue as to how the functtion createFile got separated into two functions without the conditional check. I'd appreciate if anyone can throw some light on this.

@jljorgenson18
Copy link

@jljorgenson18 jljorgenson18 commented Dec 4, 2017

The code that is calling createFile at a higher level should be figuring out which one of the two functions to call. If there are two completely different and non-intersecting blocks of code in a function, then chances are that the function is not just doing one thing. If you were to expand the fs.create blocks in the function to be 20 lines long each, things may make more sense on why you would want to split them.

@kanalasumant
Copy link
Author

@kanalasumant kanalasumant commented Dec 4, 2017

Hmm, so at the higher level, one would probably use an if statement anyway to determine which call. Sounds good. Will try it. Thanks @jljorgenson18 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.