DEV Community

Sealtiel
Sealtiel

Posted on • Originally published at codefile.blogspot.com on

Flag Arguments

Passing a boolean as an argument into a method is not good practice. It complicates the method signature, indicating that this method does more than one thing. It does one thing if the flag is true and another if the flag is false!

A method or function should do one thing and do it well.

In order to avoid passing flag arguments you should split the method or function into two, using a very descriptive name for each of the methods.

Try refactoring the code in your current project and see if this small change improves the readibility.

Top comments (0)