[thelist] EASY ONE - Nested IF statements

Ken Schaefer ken at adOpenStatic.com
Fri Jul 30 23:27:07 CDT 2004


I think what you're trying to do is "refactor" your code. There are books on
this topic that illustrate common code patterns and how they can be
simplified by breaking out code into simpler, re-usable (and thus more
robust and extensible) code. Additionally, some IDEs (like VS.NET 2005) have
some built-in tools for performing refactoring.

If you're having problems determining the optimum placement of conditional
statements, then it may help to draw a Venn diagram that shows you
diagrammatically the possible sets that you have. That will help you produce
the smallest number of conditionals.

However, my suggestion would be to determine the common code operations that
you need to perform, and break those out into separate routines. How you
would implement the controller would depend on what type of outcome
possibilities you have.

For example conditions 2 & 3 below are not mutually exclusive to condition
4. Whereas if you have said:

2) vfname is null and vlname is not null
3) vlname is null and vfname is not null
4) vlname is null and vfname is null
you'd need something that could give you at least 3 distinct states.

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Brian Delaney" <brian.delaney at mccmh.net>
Subject: [thelist] EASY ONE - Nested IF statements


: I am trying to improve some code that is using nested IF statements (asp)
: 3 variables are passed to a new page where they are processed:
: vlname,vfname,vagency
:
: Here are the possible conditions:
:
: vagency = NULL
: vfname = NULL
: vlname = NULL
: vlname & vfname = NULL
: vlname = partoflastname AND vfname = partof firstname
: vlname = o'neil
: vlname = o'brien
: vlname = somelastname
: vfname = somefirstname
: vagency = ALL
: vagency = someagency

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the thelist mailing list