Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operand order, an inspection for #2219

Open
ThunderFrame opened this issue Sep 6, 2016 · 2 comments
Open

Operand order, an inspection for #2219

ThunderFrame opened this issue Sep 6, 2016 · 2 comments
Labels
difficulty-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections up-for-grabs Use this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky

Comments

@ThunderFrame
Copy link
Member

In comparison conditions, code is more readable when the operands are in a readable order, unlike the following:

    Dim widget As Long
    widget = 5

    If 5 = widget Then
        Beep
    End If

    If 4 + 2 = widget Then
      Beep
    End If

    While 10 > widget
      widget = widget + 1
    Wend

    Select Case True
      Case 15 > widget
         Beep
      Case Else
    End Select

Granted, some might argue that this is a matter of personal preference, and there are some special situations where both operands are suitable for either side of the comparison.

Dim j
Dim i
For i = 1 to 10
  For j = 1 To 10
    'Does i come before j because i is assigned before j, or does j come before i because j is declared before i?
    If i = j Then
      Beep
    End If

    'What happens when there's a calculation on both sides of the comparison?
    If i + 2 = j + 3 Then
      Beep
    End If
  Next j
Next i
@retailcoder
Copy link
Member

In other words, a Yoda Condition inspection?

@Vogel612
Copy link
Member

Vogel612 commented Sep 6, 2016

Shouldn't be too hard to implement, I'd say it's nothing we should be interfering with though. The only thing where this could be useful IMO is in some "inconsistent conditional ordering" inspection, which would evaluate all conditionals and flag all that don't follow the majority. That's something I could get behind

@retailcoder retailcoder added the up-for-grabs Use this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky label Sep 6, 2016
@retailcoder retailcoder changed the title Inspection for comparison operand order Operand order, an inspection for Feb 16, 2017
@retailcoder retailcoder added the difficulty-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. label Feb 16, 2017
@Vogel612 Vogel612 added enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. and removed feature-request labels Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections up-for-grabs Use this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky
Projects
None yet
Development

No branches or pull requests

3 participants