clean-code-javascript icon indicating copy to clipboard operation
clean-code-javascript copied to clipboard

Don't use flags as function parameters

Open kanalasumant opened this issue 7 years ago • 2 comments

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.

kanalasumant avatar Dec 04 '17 03:12 kanalasumant

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.

jljorgenson18 avatar Dec 04 '17 07:12 jljorgenson18

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 !

kanalasumant avatar Dec 04 '17 15:12 kanalasumant