ryanmcdermott / clean-code-javascript

:bathtub: Clean Code concepts adapted for JavaScript
MIT License
91.24k stars 12.23k forks source link

Don't use flags as function parameters #235

Open kanalasumant opened 6 years ago

kanalasumant commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 !