Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll suggest this 'improvement'.</p> <ul> <li><p><code>get_binary_mode()</code> gets called once. a bit of a performance gain.</p></li> <li><p>Your 3 cases for listVersion.value are still 3, but easier to read. When you need to add a 4th, it's a simple job to add another <code>Case</code> and <code>Exit Select</code>. Be sure to keep the <code>Exit Select</code> statements in case a value like <code>9</code> comes along, as it satisifes both <code>&lt;10</code> and <code>&lt;27</code>.</p></li> <li><p>a separate function and separation of logic for each case (under 10, under27, etc). This should be more maintainable in the future. </p></li> <li><p>When something needs changing, we know exactly where to go, and it's very localized. </p></li> <li><p>Obviously my naming conventions need some work to have the intent expressed in more human readable/understandable terms.</p></li> <li><p>certainly this answer contains more lines of code. I'd rather read &amp; maintain smaller self-contained functions that do one thing (and one thing well). YMMV.</p></li> <li><p>you could go one step further and get rid of the local variable <code>bits</code>. Simply <code>Return AnalyzeUnderXX()</code>.</p></li> </ul> <pre><code>Private Function get_number_of_bits() As Integer Dim mode As String = get_binary_mode(listMode.SelectedItem) Dim bits As Integer Select Case Convert.ToInt32(listVersion.Value) Case Is &lt; 10 bits = AnalyzeUnder10(mode) Exit Select Case Is &lt; 27 bits = AnalyzeUnder27(mode) Exit Select Case Else bits = AnalyzeDefault(mode) End Select Return bits End Function Private Function AnalyzeUnder10(input As String) As Integer Select Case input Case "0001" Return 10 Case "0010" Return 9 Case "0100" Or "1000" Return 8 End Select End Function Private Function AnalyzeUnder27(input As String) As Integer Select Case input Case "0001" Return 12 Case "0010" Return 11 Case "0100" Return 16 Case "1000" Return 10 End Select End Function Private Function AnalyzeDefault(input As String) As Integer Select Case input Case "0001" Return 14 Case "0010" Return 13 Case "0100" Return 16 Case "1000" Return 12 End Select End Function </code></pre>
    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.
 

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