[Gambas-user] Better use of prefixes

Cristiano Guadagnino criguada at gmail.com
Sun Mar 17 12:14:03 CET 2019


Personally, I would really hate having to read code formatted as you
propose.
I prefer the original by a long shot.

Cris


Il giorno sab 16 mar 2019 alle ore 18:57 Cedron Dawg <cedron at exede.net> ha
scritto:

> More readable for whom?
>
> (...)


> The Original:
>
> Private Sub SameSetting(vOld As Variant, vNew As Variant) As Boolean
>
>   Dim I As Integer
>   Dim vOldVal As Variant
>   Dim vNewVal As Variant
>
>   If IsNull(vOld) And If IsNull(vNew) Then Return True
>   If TypeOf(vOld) <> gb.Object And If TypeOf(vNew) <> gb.Object Then
> Return vOld = vNew
>
>   If Not (vOld Is Array) Then Return
>   If Not (vNew Is Array) Then Return
>   If vOld.Count <> vNew.Count Then Return
>   If vOld = vNew Then Return
>
>   For I = 0 To vOld.Max
>     vOldVal = vOld[I]
>     vNewVal = vNew[I]
>     If TypeOf(vOldVal) = gb.Object Or If TypeOf(vNewVal) = gb.Object Then
> Return
>     If vOldVal <> vNewVal Then Return
>   Next
>
>   Return True
>
> End
>
>
> Here is how I would have code it:  (Notice how the spaces inside the
> parentheses also improve readability.)
>
>
>
> '=============================================================================
> Private Sub SameSetting( argOldValues As Variant, argNewValues As Variant
> ) As Boolean
>
> '---- Bail as Matching if Both Null
>
>         If IsNull( argOldValues ) And If IsNull( argNewValues ) Then
> Return True
>
> '---- Bail On Simple Variables Comparison
>
>         If TypeOf( argOldValues ) <> gb.Object And If TypeOf( argNewValues
> ) <> gb.Object Then Return ( argOldValues = argNewValues )
>
> '---- Bail as not Matching on Non-Array Objects
>
>         If Not ( argOldValues Is Array ) Then Return False
>         If Not ( argNewValues Is Array ) Then Return False
>
> '---- Bail as not Matching on Count Comparison
>
>         If argOldValues.Count <> argNewValues.Count Then Return False
>         If argOldValues = argNewValues Then Return True '??????????   Same
> Array should be True, No?
>
> '---- Bail on any Mismatched Array Elements
>
>         Dim i As Integer
>         Dim theOldValue As Variant
>         Dim theNewValue As Variant
>
>         For i = 0 To argOldValues.Max
>           theOldValue = argOldValues[i]
>           theNewValue = argNewValues[i]
>           If TypeOf(theOldValue) = gb.Object Or If TypeOf(theNewValue) =
> gb.Object Then Return False
>           If theOldValue <> theNewValue Then Return False
>         Next
>
> '---- Exit as Matching
>
>         Return True
>
> End
>
> '=============================================================================
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190317/06a95395/attachment.html>


More information about the User mailing list