Re: CFC argument best practice question
On Mon, Mar 7, 2011 at 10:56 AM, Nathan Strutz wrote: > If you have a lot of arguments, one way to refactor that is to make a > component that encompasses those arguments - essentially a bean, maybe a > couple of beans if the arguments are unrelated. In your first public method, > instantiate that bean with the arguments, then just pass that bean around. > Follow that, and you've gone from just using components to actual > object-oriented programming. Hardly. A bean that's just a glorified struct with dumb get/set methods isn't OOP, it's just a struct with overhead. Frankly, creating new components just to group related arguments is a waste of time in CFML and just slows down your code. In answer to Brook's original question: yes, it is probably better practice to declare the arguments in the private method, for documentation purposes, especially if you are referring to those arguments in the code... -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342942 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: CFC argument best practice question
On Mon, Mar 7, 2011 at 11:57 AM, Judah McAuley wrote: > > On Mon, Mar 7, 2011 at 9:24 AM, Matt Quackenbush wrote: > > That's the beauty of refactoring, though. Unless you need to, don't. > And > > if no other method is calling it (or expected to call it), then it is not > > needed. If it becomes needed, refactor and add it in. :-) > > I generally agree with this notion but I think it starts to fall apart > with more complex methods. You might have a whole routine that only > gets called one place but is complex enough that there are benefits to > breaking it up into multiple methods that have single concerns. Doing > so makes it easier to debug (the method names provide helpful clues to > follow the chain of execution) and makes it much easier to unit test. > I totally agree. I was trying to approach it from the perspective of a n00b, though. (Hence the overly generalized statement.) I was figuring that the OP is not unit testing or writing up huge, complex methods. My apologies if I misunderstood the OP's current level of experience with these concepts. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342809 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: CFC argument best practice question
> I generally agree with this notion but I think it starts to fall apart > with more complex methods. You might have a whole routine that only > gets called one place but is complex enough that there are benefits to > breaking it up into multiple methods that have single concerns. Doing > so makes it easier to debug (the method names provide helpful clues to > follow the chain of execution) and makes it much easier to unit test. Yeah, this is what I was trying to get at. I don't want to go through hundreds of lines of code at once if I can avoid it. >> Either way, though, the arguments should be clearly defined. > > Agreed. I agree with that too. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342808 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: CFC argument best practice question
On Mon, Mar 7, 2011 at 9:24 AM, Matt Quackenbush wrote: > That's the beauty of refactoring, though. Unless you need to, don't. And > if no other method is calling it (or expected to call it), then it is not > needed. If it becomes needed, refactor and add it in. :-) I generally agree with this notion but I think it starts to fall apart with more complex methods. You might have a whole routine that only gets called one place but is complex enough that there are benefits to breaking it up into multiple methods that have single concerns. Doing so makes it easier to debug (the method names provide helpful clues to follow the chain of execution) and makes it much easier to unit test. > Either way, though, the arguments should be clearly defined. Agreed. J ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342807 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: CFC argument best practice question
If you have a lot of arguments, one way to refactor that is to make a component that encompasses those arguments - essentially a bean, maybe a couple of beans if the arguments are unrelated. In your first public method, instantiate that bean with the arguments, then just pass that bean around. Follow that, and you've gone from just using components to actual object-oriented programming. nathan strutz [http://www.dopefly.com/] [http://hi.im/nathanstrutz] On Mon, Mar 7, 2011 at 10:06 AM, Brook Davies wrote: > > Hello, > > > > Just a quick "Best Practices" question. I have a CFC, I call a method and > pass a slew of arguments to it. Internally it calls a private method using > argumentCollection=arguments. My question is, should I repeat the argument > definitions on the private method? > > > > The arguments are available regardless of whether or not the private method > has the actual argument definitions. What is the best practice here? Define > the arguments or just use them knowing they are the same as the public > method? > > > > Brook > > > > > > > > > ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342806 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: CFC argument best practice question
On Mon, Mar 7, 2011 at 11:21 AM, Dave Watts wrote: > > > If, however, multiple methods do not call that private method, then there > is > > no need for the private method to exist. > > I wouldn't go as far as that. Private methods like this can serve the > same purpose as functions or subroutines anywhere else - to limit the > amount of code in the "main" method, and to provide a basis for > refactoring if other methods may be introduced in the future. > That's the beauty of refactoring, though. Unless you need to, don't. And if no other method is calling it (or expected to call it), then it is not needed. If it becomes needed, refactor and add it in. :-) Either way, though, the arguments should be clearly defined. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342804 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: CFC argument best practice question
> If, however, multiple methods do not call that private method, then there is > no need for the private method to exist. I wouldn't go as far as that. Private methods like this can serve the same purpose as functions or subroutines anywhere else - to limit the amount of code in the "main" method, and to provide a basis for refactoring if other methods may be introduced in the future. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342803 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: CFC argument best practice question
Presumably your private method is being called by multiple methods. It is definitely much better - at least in terms of documentation - to have those arguments clearly defined. :-) If, however, multiple methods do not call that private method, then there is no need for the private method to exist. HTH ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342802 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
CFC argument best practice question
Hello, Just a quick "Best Practices" question. I have a CFC, I call a method and pass a slew of arguments to it. Internally it calls a private method using argumentCollection=arguments. My question is, should I repeat the argument definitions on the private method? The arguments are available regardless of whether or not the private method has the actual argument definitions. What is the best practice here? Define the arguments or just use them knowing they are the same as the public method? Brook ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342801 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm