Check use of parentheses with multiple logical operators in a where clause

Project:Prolint Issue Tracker
Component:Rules
Category:feature request
Priority:normal
Assigned:jurjen
Status:closed
Description

There has been a report on PSDN at http://www.psdn.com/library/thread.jspa?threadID=8706&tstart=0 that some versions of 10.1B have a problem with not following the correct precedence of multiple logical operators in a where clause. It seems to me that people are not as clear about the precedence of logical operators as they are of arithmetic operators and so one should always use parentheses to make sure that the intent is clear when there is a mixture of AND and OR


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tamhas's picture

While the trigger for the

While the trigger for the suggestion was the purported non-regression in some version of 10.1B, I would argue that people are generally not nearly as aware of operator precedence rules with logicals compared with their familiarity, also possibly limited, of operator precedence with arithmetic operators. Thus, it should be at least a stylistic rule that any time there are mixed logical operators, there should be parentheses. If people do that, we won't have any instances of the second type! :) I think it would be difficult from context to determine that there was an unintended mistake.


jurjen's picture

#1

Good idea!

But what is the proper implementation? We could just give a warning when parentheses are missing (in an expression that contains both AND and OR), or maybe raise a severe warning when precendence is probably not what the programmer intended, for example:

   company="" or company=somvariable 
   and ready=no

In the first case Prolint would probably create a whole lot of false negatives. Oh well, it is the easiest implementation, so let's just try that one first, ok?


jurjen's picture

#2

Category:support request» feature request

jurjen's picture

#3

Assigned to:Anonymous» jurjen
Status:active» fixed

Done, created new rule "andorparens". It barfs at you when it finds a mix of AND and OR without parentheses.


#4

Status:fixed» closed