"value":"\n <p>A convention I like from the Laravel framework is to avoid adding boolean arguments to methods.<\/p>\n\n<p>For example, if I have this function:<\/p>\n\n<pre><code class=\"php\">public function getPosts() { ... }\n<\/code><\/pre>\n\n<p>If I wanted to only get published posts, one way would be to add a boolean argument:<\/p>\n\n<pre><code class=\"php\">public function getPosts(boolean $onlyPublished) { ... }\n<\/code><\/pre>\n\n<p>Then, I'd need to use that within the method body to add another condition (this is referred to as control coupling, where one method affects another).<\/p>\n\n<p>The non-boolean approach would be to create a separate method with its own distinct name.<\/p>\n\n<p>For example, <code>getPosts()<\/code> could be named <code>getAllPosts()<\/code> and there could be a separate <code>getPublishedPosts()<\/code> method for only getting published posts:<\/p>\n\n<pre><code class=\"php\">public function getAllPosts() { ... }\n\npublic function getPublishedPosts() { ... }\n<\/code><\/pre>\n\n<p>Whilst we have two methods now instead of one, it's much clearer what each does and there aren't any random <code>true<\/code> or <code>false<\/code>s wherever the method is used.<\/p>\n\n ",
"format":"full_html",
"processed":"\n <p>A convention I like from the Laravel framework is to avoid adding boolean arguments to methods.<\/p>\n\n<p>For example, if I have this function:<\/p>\n\n<pre><code class=\"php\">public function getPosts() { ... }\n<\/code><\/pre>\n\n<p>If I wanted to only get published posts, one way would be to add a boolean argument:<\/p>\n\n<pre><code class=\"php\">public function getPosts(boolean $onlyPublished) { ... }\n<\/code><\/pre>\n\n<p>Then, I'd need to use that within the method body to add another condition (this is referred to as control coupling, where one method affects another).<\/p>\n\n<p>The non-boolean approach would be to create a separate method with its own distinct name.<\/p>\n\n<p>For example, <code>getPosts()<\/code> could be named <code>getAllPosts()<\/code> and there could be a separate <code>getPublishedPosts()<\/code> method for only getting published posts:<\/p>\n\n<pre><code class=\"php\">public function getAllPosts() { ... }\n\npublic function getPublishedPosts() { ... }\n<\/code><\/pre>\n\n<p>Whilst we have two methods now instead of one, it's much clearer what each does and there aren't any random <code>true<\/code> or <code>false<\/code>s wherever the method is used.<\/p>\n\n ",