Mostly because it's uber simple at this point and growing toward a deeper OO 
implementation and because it takes a great deal of explanation to take a 
strong CF developer to a well-formed OO implementation. For someone who's 
working with example code from some other source and getting intermittent 
output, pushing to far too fast only creates confusion.
 I think sometimes we answer questions that aren't being asked without 
realizing that they're not being asked because someone just hasn't gotten 
far enough into the technology to ask it. By answering it too soon we only 
create confusion for them.
 In this case, Will's working on a simple, one-off shopping cart for 
someone... it's good foundation, and like we all have, someday he'll look 
back at this and wince or at least smile and remember the good old days.
 "The cart" in this case is only one cart, and it contains a struct of 
products... so its getCartTotal method only has to total the subtotal values 
in each product. In other words there is only one cart to pass to the 
function, so the function might as well assume that for now and later, 
refactor refactor refactor. In all, what's most important is to not but The 
Cart before The Horse and get things even more muddled before it's been made 
to work the first time round.
 And just out of curiosity, how is that a best practice? I'm not sure I 
follow the logic... if I have one cart/session in session.cart, and I want a 
subtotal of that cart, how is session.cart.getTotal(session.cart) a best 
practice and who's best practice is it? ;)
 Laterz,
J

 On 4/28/05, Joe Rinehart <[EMAIL PROTECTED]> wrote: 
> 
> Will,
> 
> Why do you reference variables.cart in your function? It'd be more of
> a best practice to pass GetCartTotal the cart in question, like so:
> 
> 
> <cffunction name="GetCartTotal" access="public" returntype="numeric"
> output="true" hint="Show total of cart in dollars">
> <cfargument name="cart" required="true" type="struct" hint="I am the
> cart to total">
> <cfset var cartTotal = 0>
> <!--- Don't forget implicity created variables need declaration too! --->
> <cfset thismerchID = "">
> <cfloop collection="#arguments.cart#" item="thismerchID">
> <cfset cartTotal = cartTotal + arguments.cart[thismerchID]["subtotal"]>
> </cfloop>
> <cfreturn cartTotal>
> </cffunction>
> 
> Then, in your calling code, do:
> 
> GetCartTotal(variables.cart) instead of GetCartTotal()
> 
> -Joe




-- 
---------------
-------------------------------------
Buy SQLSurveyor!
http://www.web-relevant.com/sqlsurveyor
Never make your developers open Enterprise Manager again.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:204996
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to