Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two issues to address here: readability and understandability</p> <p>The "readability" solution is a style issue and as such is open to interpretation. My preference is this:</p> <pre><code>if (var1 == true &amp;&amp; // Explanation of the check var2 == true &amp;&amp; // Explanation of the check var3 == true &amp;&amp; // Explanation of the check var4 == true &amp;&amp; // Explanation of the check var5 == true &amp;&amp; // Explanation of the check var6 == true) // Explanation of the check { } </code></pre> <p>or this:</p> <pre><code>if (var1 &amp;&amp; // Explanation of the check var2 &amp;&amp; // Explanation of the check var3 &amp;&amp; // Explanation of the check var4 &amp;&amp; // Explanation of the check var5 &amp;&amp; // Explanation of the check var6) // Explanation of the check { } </code></pre> <p>That said, this kind of complex check can be quite difficult to mentally parse while scanning the code (especially if you are not the original author). Consider creating a helper method to abstract some of the complexity away:</p> <pre><code>/// &lt;Summary&gt; /// Tests whether all the conditions are appropriately met /// &lt;/Summary&gt; private bool AreAllConditionsMet ( bool var1, bool var2, bool var3, bool var4, bool var5, bool var6) { return ( var1 &amp;&amp; // Explanation of the check var2 &amp;&amp; // Explanation of the check var3 &amp;&amp; // Explanation of the check var4 &amp;&amp; // Explanation of the check var5 &amp;&amp; // Explanation of the check var6); // Explanation of the check } private void SomeMethod() { // Do some stuff (including declare the required variables) if (AreAllConditionsMet (var1, var2, var3, var4, var5, var6)) { // Do something } } </code></pre> <p>Now when visually scanning the "SomeMethod" method, the actual complexity of the test logic is hidden but the semantic meaning is preserved for humans to understand at a high-level. If the developer really needs to understand the details, the AreAllConditionsMet method can be examined.</p> <p>This is formally known as the "Decompose Conditional" refactoring pattern I think. Tools like Resharper or Refactor Pro! can making doing this kind of refactoring easy!</p> <p>In all cases, the key to having readable and understandable code is to use realistic variable names. While I understand this is a contrived example, "var1", "var2", etc are <strong>not</strong> acceptable variable names. They should have a name which reflects the underlying nature of the data they represent.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload