Don’t use flags as function parameters

Don’t use flags as function parameters

Tags
Clean Code
Javascript
Software Development
Published
Published July 11, 2022
Author
Due Date
 
☑️ Topic: Functions
 
☑️ Idea: Flags tell you that a function does more than one thing. Functions should do only one thing.
 
☑️ Benefits: Readability, reusability, testability
 
☑️ Guideline: If you find different code paths in a function based on a Boolean parameter, create 2 functions instead.
 
// BAD function createFile(name, temp) { if (temp) { fs.create(`./temp/${name}`); } else { fs.create(name); } } // GOOD function createFile(name) { fs.create(name); } function createTempFile(name) { createFile(`./temp/${name}`); }