Friday, December 8, 2006

Using a Compound List to Simulate a Compound Boolean Statement

I was once asked to build an application that would use the demographic information submitted by would-be students to ensure that they were eligible to participate in certain social and cultural discussion sections. Each discussion section would have a number of enrollment rules that would not only determine which students were eligible, but would also set a limit on how many students could enroll for that discussion under that rule. For example, one of these enrollment rules would say "allow 5 students who are freshman or sophomores and were born in the U.S. and are atheists or agnostics and who grew up in a rural or suburban area to enroll in this discussion."

I knew I had to find a way to handle these complex evaluations in a flexible manner without resorting to multiple layers of if/else statements. Fortunately, I figured out a way to use compound lists to evaluate a student`s eligibility.

For any non-ColdFusion programmers who might be listening, ColdFusion has a number of functions for processing lists, lists being strings that can be divided into separate pieces by a delimiter character, usually a comma. For example, the function ListGetAt("red,blue,green,yellow",2,",") would return the value "blue" (the second item in the string where each item is separated/delimited by a comma). Other functions in ColdFusion can make use of lists, such as the tag, which can loop through each item in a list one at a time.

Because it`s possible to designate any characters (or even a string of characters) as the delimiter in a list function, the same string can be evaluated as different lists, and I used this fact to create my evaluation routine. I wrote code that translated the enrollment rules into lists where an AND operator was represented by a pipe (|) character and the OR conditions were separated by commas. So the enrollment rule I used earlier was translated into:


I then wrote code to write all of the demographic data that was entered by the student into a simple comma-delimited list.

To determine if a student was eligible to enroll in a discussion, the evaluation code would count the number of AND operators in the enrollment rule (in this example, 4). The code would then run an outer loop that would loop through all of the AND operators one at a time. Inside this outer loop would be a second loop that would loop through all of the OR conditions one at a time. If the ListFind function determined that any of the OR conditions in the enrollment rule were present in the demographic list, a counter variable would be incremented. If, at the end of both loops, the counter variable value matched the number of AND operators in the enrollment rule, that meant that the student was eligible. Here is the code:

For more information on ColdFusion functions regarding lists, check out the List functions at cfQuickDocs, an AJAX-powered ColdFusion documentation site.

Wednesday, November 29, 2006

Web Developers and User Interfaces

Web application developers (the folks who program the functionality of the web application) are lousy user interface developers. That`s an assertion one hears a lot in the web designer and developer community, and was repeated again today in to an article entitled "This Is What Happens When You Let Developers Create UI."

But in application development, as in life, there are no absolutes. I`m sure there are many web developers like me who have to handle every aspect of the development process, including the design of the UI.

I've learned that the best way to avoid designing a programmer-friendly UI instead of a user-friendly UI is to work with your client to come up with the user interface first, and let the user interface dictate the functionality of your application instead of having the functionality drive the design of the interface. This is one of the ideas behind the Fusebox Lifecycle Process (FLiP), a development methodology where the user interface is finalized and the application structure is completely planned out and architected before any programming is done. Although originally designed for use with the Fusebox application framework, FLiP can be applied to any software development process, and going through the process of hashing out the user interface with your client before coding any of the application logic goes a long way towards removing any surprises or last-minute course changes at the end of the development process.

And there is one advantage to being both the programmer and the interface designer: I can make sure that the interface doesn`t require any functionality that is beyond my ability to program. :)

Tuesday, November 28, 2006

Welcome to my blog

Hello! My name is Brian, and welcome to my blog.

Starting tomorrow, I`ll be using this blog to share my knowledge and experience as an intermediate-level ColdFusion web application developer, any resources I come across that I think would be useful to other web application developers, and ...well...anything else I think is worth talking about. :)

Until then, check out the links over on the right for some ColdFusion and web development resources.