1. Technical Field of the Invention
This invention relates to computer programming. More particularly, it relates to alternatively re-organizing complex IF-THEN clauses as case statements based on binary condition strings.
2. Background Art
In very complex agents, nested IF-THEN clauses can become unwieldy, adversely affecting program performance through unnecessary and/or redundant checking of conditions.
In addition, complex nesting of IF-THEN clauses results in program code that is very difficult for the programmer maintain and enhance. Nested IF-THEN clauses, even with simple conditions and code blocks, are often inherently difficult for many programmers to navigate through during maintenance. When the evaluated conditions and code blocks requiring conditional execution become complex, the problem is exacerbated. Despite the best efforts of the original programmer to comment the code, steep learning curves result for future programmers inheriting it. Additionally, the code becomes much more prone to logic errors and even more redundancy.
A system, method and program storage device are provided for executing complex nested if-then statement on data objects in a digital computer by organizing the if-then statements as a plurality of logical case statements; for each case statement, providing a set of binary condition arrays; determining a condition set for a data object; and executing on the data object a case statement for which a condition array from the set of binary condition arrays matches the condition set for the data object.
Other features and advantages of this invention will become apparent from the following detailed description of the presently preferred embodiment of the invention, taken in conjunction with the accompanying drawings.
In accordance with the preferred embodiment of the invention, complex nested if-then clauses are implemented as case statements with conditions represented as binary arrays.
Referring to
Referring to
Condition set object includes first condition (indicia representing an attribute, variable, or other value characteristic of a data object) 142, second condition 144, and so on to Nth condition 146. (In the example of
Case statement object 150 includes first case statement 152, second case 154, and so on to Mth case 156. Each of these case statements includes respective binary conditions arrays 160, 162, 164 for selecting the case, and code for executing the case on data satisfying its conditions array. (In the example of
Referring further to
Referring to
Processing of input data begins with a list of sorted objects 100 (See also
In step 122, the next case statement 150 is selected, and in step 110 the condition string for this object 194 is compared, as is represented by line 191 in
If a match is found in step 112, in step 114 the code for this case is executed. If no match is found in step 112, if in step 116 it is determined that there are more binary condition arrays for this case statement, then processing returns to step 110. (For example, in
Referring to
Referring to
In the example of
As is represented by line 191, and as has been previously described, the condition string for this data object (one of strings 190) is compared with condition arrays 160, then 162, then 166, then 168, then 164 until a match is found and the corresponding case statement 150 is executed on that data.
Referring to Table 1, an example illustrates (primarily in pseudo code) the process by which various conditions are checked prior to entering the case statement, and then arranging the case statement logically to optimize performance, readability and maintainability.
In the example of Table 1, a billing agent characterized by IF THEN statements of extreme complexity represented a maintenance nightmare. This was adapted by the process of
It is an advantage of the invention that there is provided an improved system, and method for structuring complex nested if-then clauses.
It will be appreciated that, although specific embodiments of the invention have been described herein for purposes of illustration, various modifications may be made without departing from the spirit and scope of the invention. Referring to
Further, each step of the method may be executed on any general purpose computer, such as IBM Systems designated as zSeries, iSeries, xSeries, and pSeries, or the like and pursuant to one or more, or a part of one or more, program elements, modules or objects generated from any programming language, such as C++, Java, Pl/1, Fortran or the like. And still further, each said step, or a file or object or the like implementing each said step, may be executed by special purpose hardware or a circuit module designed for that purpose.
Accordingly, the scope of protection of this invention is limited only by the following claims and their equivalents.
This application is a continuation of and claims priority to U.S. patent application Ser. No. 11/014,285 filed 16 Dec. 2004 now U.S. Pat. No. 7,328,203 by Matthew J. Bangel, Scott D. Hicks, and James A. Martin for System and Method for Executing Complex IF-THEN Clauses.
Number | Name | Date | Kind |
---|---|---|---|
4034195 | Bates | Jul 1977 | A |
5187330 | Holcroft | Feb 1993 | A |
5652580 | Saxena | Jul 1997 | A |
5966376 | Rakib et al. | Oct 1999 | A |
5991308 | Fuhrmann et al. | Nov 1999 | A |
6044063 | Kolagotla et al. | Mar 2000 | A |
7328203 | Bangel et al. | Feb 2008 | B2 |
Number | Date | Country | |
---|---|---|---|
20080082474 A1 | Apr 2008 | US |
Number | Date | Country | |
---|---|---|---|
Parent | 11014285 | Dec 2004 | US |
Child | 11983465 | US |