I was working on a problem the other day. I was following my own best practices
- think critically
- think first
- avoid implementation while thinking
- think maintainability
I was trying to figure out the best way to solve a problem. I had given it a good initial analysis, but i was also dealing with a deadline, so i was feeling pressure to get to implementation. I gave in to this pressure, against my better judgement, and was 2 or 3 hrs into implementing a solution. The solution had me adding knowledge of one service into another via our coldspring container (which in itself is fine) and then using the new service in the old one to do a lookup of a bean to get a value that would determine which of two methods to call in a gateway. All the while, i was feeling like i was missing something easier. I just had that feeling that my solution was too complicated for what i was trying to do.
The problem in a high level nutshell was this: i had certain records in an association table that i sometimes wanted to be included in the return set of a look up, depending on where it was being called from. There were some records that i did not want included other times. It wasn't until the third day that i had been looking at this problem that i saw what i was really trying to do, which was simply to ignore certain records in the association table ALL THE TIME. I just did not see this at first. I actually opened the association table and was looking at the columns in the table talking out load through the problem when i saw the simple solution. I knew in about 10 seconds that this was the better solution.
I checked out of our repository the files that i had already updated, i think there was 3, and started back at point A with my new solution, which from a code standpoint was one single line of SQL in one function that omitted the records when a field was set to 0.
My solution was in the DB, not the code. I ended up simply adding a bit field to the table, setting it to 1 (default value for all records) since all but about 100 of the 7000 records in the table would remain in play and changing the records that i did NOT want in play to 1. Then added the line to the function that conditionally omitted the recs set to 1.
The trade off is a check on this new bit field for every look up to the table and the need to update each new record that falls into the value = 1 category. The gain is a simple, maintainable solution with little to know memory overhead.
Monday, December 1, 2008
Subscribe to:
Post Comments (Atom)
1 comment:
I like how I think...)
Post a Comment