Now it seem that the functionality of the two queries is close enough that you could do something like this (option #1):
SELECT id, name FROM my_table <cfif structKeyExists(arguments, "passedVal")> WHERE col = <cfqueryparam value="#arguments.passedVal#" ... /> </cfif> ORDER BY name, id If that works for your situation, that's what I'd do, I think. Unless the name field is friggin' huge (which I wouldn't imagine), the overhead of transfering it back from the DB server will be so tiny as to be insignificant. If you can't use the same SQL, just optionally injecting a conditional, then I'd vote for option #2, and make two completely separate methods, where the parameter is required for the parameterized one. I'd never go for option #3 (with the standard 'never' caveat ;), because you're introducing a behaviour determining parameter, which is generally considered bad OO design. Now it's a subtle point compared to option #1, granted, but here's my reasoning: With #1, you're using a parameter to narrow a search, which with #3, you're using a parameter to select between two completely different searches (even though they happen to be almost identical in this case). As a final argument against both #2 and #3, they're both making maintenance harder (either double SQL or double method), and if you're willing to pay that price for the miniscule amount of speed that not returning the name will save you, CF is a bad choice of platforms. I know you like CF (as do I), but I don't think anyone will disagree that CF isn't the best route if speed is the primary concern. But as I'm sure you'll also agree, speed is almost never the primary concern. And as a final argument against #1 and #3, if the two pieces of functionality ever diverge at all, you're forced to change your API in a more drastic manner. If you have two methods to begin with, the two can vary independantly. You could, of course, use two methods (#2) that both delegate to a private third method (#1) to get easier maintenance but the added flexibilty, if you don't mind the extra method call in there (which will cost you a handful nanoseconds). Oof. Must be late at night. I'm getting long-winded. Oops. cheers, barneyb cheers, barneyb On 12/18/05, Michael Dinowitz <[EMAIL PROTECTED]> wrote: > This is more of a style question than anything else. Lets say you have a CFC > that will be doing all the work for an application. There is need for two > different queries. The first gets an ID based on a passed value. The second > uses the same table but returns the id as well as a name and does not need a > passed value. Now here's the style question: > Do you write one function that will return both pieces of data and does a > CFIF to see if a value was passed? > Do you do two functions with each one doing exactly what is needed? > Do you write a single function that has a CFIF with two totally different > queries? > > Not a killer question, but one of style that should be investigated. I'm > doing the third option as I want very tight data transfer but also fewer > functions. Of course, if someone has a really good argument for one of the > other styles I'll re-evaluate my decision. :) > -- Barney Boisvert [EMAIL PROTECTED] 360.319.6145 http://www.barneyb.com/ Got Gmail? I have 100 invites. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:227258 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

