Now I remember why I do this job...

| | Comments (0) | TrackBacks (0)

Today I had one of those days you get as a programmer, when everything coalesces in a perfect way to shine a happy light on the universe. I had a list of bugs and a single feature I wanted to add to my Flex program. The single feature (dynamic filtering based on values in a set of arrays) took me a long time, and I wrestled with it mightily for several hours. I wanted desperately to make a filter which was extensible, which was easy to add new fields to, and passing variables around in Flex is not something I've become comfortable with.

So there I was, pounding my head against the thing, frustrated and feeling incompetent, until 4PM when a light shined down upon me from the sky, the scales fell from my eyes, whatever cliche you want to use... and the feature was complete. And when the dust cleared, I realized that 3 of the bugs on my 'to-do' list had gotten fixed in the process of creating this feature.

It's an awesome day when you feel "done" with what you're working on. I wasn't even tempted to start on something else... I just basked in the glow of having gotten it done.

For anyone wandering here from flex land who wants to see the code, here it is:

private var filterObj:Object = {this:filterThis,that:filterThat};

// These arrays are populated elsewhere with a list of strings to filter on
private var textObj:Object = {this:"",that:""};

private function filterAll():void {
var filtered:Boolean = false;
var filterType:String;

for (filterType in filterObj) {
if (filterObj[filterType].length > 0)
filtered = true;
}

if (filtered) {
dataSet.filterFunction = filterGeneralSet;
dataSet.refresh();
} else {
dataSet.filterFunction = null;
dataSet.refresh();
}

private function filterGeneralSet(item:XML):Boolean {
var filterType:String;
var element:String;
var myArray:Array;

// This is an 'and' filter where everything has to match for the element to return true
for (filterType in filterObj) {
if (filterObj[filterType].length > 0) {
myArray = filterObj[filterType];
for each (element in filterObj[filterType]) {
var itemFilter:String = item.child(filterType)[0];
if (itemFilter != element) {
return false;
}
}
}
}
return true;
}

0 TrackBacks

Listed below are links to blogs that reference this entry: Now I remember why I do this job....

TrackBack URL for this entry: http://www.princesspolymath.com/cgi-bin/mt/mt-tb.cgi/17

Leave a comment

About this Entry

This page contains a single entry by Synedra published on October 8, 2007 9:00 PM.

Perl Docs vs. Other Docs was the previous entry in this blog.

Perl Makes Good Programmers is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.