Quantcast
Channel: Is it always possible to separate multiple conditions in an IF statement into individual statements? - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 2

Is it always possible to separate multiple conditions in an IF statement into individual statements?

$
0
0

I'm trying to find the simplest way to model user-defined conditional statements without resorting to text parsing. This is fairly easy when there is only one condition in the statement because you can split that into an operand, a comparison operator, and a value to compare with. Just store those three and you can let the user use dropdown boxes to select values and an operator from a predefined list.

In this example imagine the code snippet text is a dropdown box and bold text is uneditable:

IF(select value)is(select comparison operator)(enter value)then...

Clarification - so the bit between IF and IS is a dropdown box with an object's member or database field in, the comparison operator is a dropdown box with options such as "equal to" or "greater than", and the final box is a typeable text box where the user can enter the value manually.

But occasionally they will need to test multiple conditions before executing whatever action they define. Microsoft Dynamics CRM does this quite well with their business rules (which is similar to what I am trying to achieve) as you can see here.

In simple examples, you can rearrange it into nested if statements, although you may end up repeating yourself if using a lot of ORs. It's not the prettiest solution in the world but at the end of the day it works and you don't run the risk of allowing the user to type badly formed input. I anticipate complex multiple conditional logic to be an edge case for this project so the messiness is (mostly) justified.

The million dollar question is are there any cases where conditional logic cannot be represented like this?

EDIT in order to explain how this question is not a duplicate of this one, that question is not (as far as I can tell) asking the same thing. Although both questions deal with evaluating unknown variations of Boolean expressions, I am asking if my solution will allow me to represent all feasible expressions with a particular method, while that question is asking about unit testing for Boolean expressions with many inputs.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images