Re: How can this CFC be improved?
Now *that* would be scary this close to Halloween! :oP Dawson, Michael wrote: > Oh, and VAR your variables!!! > > If you don't, Ray Camden will be knocking at your door. > > Mike > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314272 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: How can this CFC be improved?
Oh, and VAR your variables!!! If you don't, Ray Camden will be knocking at your door. Mike -Original Message- From: Rick Faircloth [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 22, 2008 1:26 PM To: cf-talk Subject: Re: How can this CFC be improved? I think I can handle that approach and stay sane! :o) ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314271 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
I think I can handle that approach and stay sane! :o) Charlie Griefer wrote: > For now I probably wouldn't worry about DAOs and other related concepts. > Build a strong foundation by encapsulating the CFC methods so that they > don't rely on any external variables. That'd be a good start. > Once you recoil in terror at seeing a CFC method reference application or > session or form or (etc), then you're ready to take the next step :) > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314269 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
For now I probably wouldn't worry about DAOs and other related concepts. Build a strong foundation by encapsulating the CFC methods so that they don't rely on any external variables. That'd be a good start. Once you recoil in terror at seeing a CFC method reference application or session or form or (etc), then you're ready to take the next step :) On Wed, Oct 22, 2008 at 11:09 AM, Rick Faircloth <[EMAIL PROTECTED]>wrote: > Thanks for the overview, Mike. > > I see what everyone's saying about the encapsulation. I'm just trying to > make all the pieces of the puzzle fit. Your tutorial was helpful. It > was a little > advanced in some respects. I just needed to approach the CFC's a little > more carefully, until I could figure out what was going on, before trying > to > really understand the DAO approach. > > I'm sure to have a "eureka" moment at some point, with everyone's help..and > I'm sure it'll be on a Sunday night...my "honey, don't forget to take > out the garbage" night! :o) > > Rick > > Mike Kear wrote: > > Rick, imagine how it would be if (as is fairly common) you have > > business objects (beans) handling single items, and DAO cfcs handling > > all the database interaction back and forth.This is the scenario i > > drew in the tutorials I wrote ... > > > > So in the application scope you have a DAO - just one . sitting in > > RAM waiting to be called on. And as people come and go through the > > site they're causing beans to be created all over hte place to > > manipulate the things they're needing as they move around. > > > > If (as happens frequently in one of my sites) there are 400 > > concurrent users, and only one DAO for this applicatoin, imagine how > > many people are likely to be simultaneously using an "Add()" method in > > the DAO. In those circumstances it's absolutly essential that the > > methods in teh DAO to e threadsafe. That means ALL variables inside > > the methods have to be var'd unless there is a specific reason not to. > > It means you have to build teh DAO carefully so data from one user > > doesn't interfere with the data from the others. But that's also true > > if you only have 3 simultaneous users. You still dont want their > > information - maybe their shopping carts getting intermingled. > > > > But on the other hand if you dont have the DAO sitting in the > > application scope, every time anyone uses that part of the > > application, the DAO has to be instantiated again.There's an > > overhead processing price to pay for doing that. > > > > Here's my rule of thumb. Vary away from it only once you realise > > the implications ... never require a cfc to know anything about the > > outside world. Anything it needs to know, you'll tell it. So > > that means you tell it what the dsn is. you dont ask it to go look > > in the application vars for it. You tell ilt what the different > > values are for the arguments, either by passing in a struct such as > > form struct or by passing in the values individually or by passing in > > a bean. But the cfc doesnt have to go looking for it, and doesnt > > have to know where it came from > > > > This is exactly how most of the built-in functions in coldfusion work. > >The function replace() doesnt have to know anything - you give it > > the information it needs to do its job.the replace() function > > doesnt do much - it does a limited job quickly and efficiently but > > its a small job.that's how to design your methods in you own cfcs > > - small limited functions that dont know anything about the outside > > world apart from what you tell it, and they should be threadsafe so > > you dont have to use up all your ram and processing power with > > bazillions of copies of the same code running at once. > > > > Hope this helps I rather have the feeling that at the moment > > you're thinking the stuff i put in my tutorial is a lot of additional > > typing - it's all too hard and too much work. That's not a problem > > - it was for me too until suddenly the light went on and i had a few > > of those "EUREKA!!" moments. I can disctinctly remember the day i > > finally 'got it' about encapsulation.I was so excited i made the > > mistake of talking about it in an agitated manner to my wife to > > promptly told me to stop being so bloody stupid and put the garbage > > out cos it's garbage night. > > > > > > Cheers > > Mike Kear > > Windsor, NSW, Australia > > Adobe Certified Advanced ColdFusion Developer > > AFP Webworks > > http://afpwebworks.com > > ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month > > > > > > > > On Thu, Oct 23, 2008 at 3:39 AM, Rick Faircloth > > <[EMAIL PROTECTED]> wrote: > > > >> I think I'm beginning to understand your reasoning. > >> It's just taking some time for me to get to the "best practices" of CFC > >> usage. > >> Trying to get "anything" to work at first keeps my projects moving, > while > >> beginning to employ diffe
Re: How can this CFC be improved?
Sounds like a good approach. I'm about to duplicate much of the work I've done on a recent project for another client and I plan to use CFC's instead of putting the code into my .cfm's. (I wouldn't call what I'm going to do "OOP"... :oP) But since I've already written the code procedurally once, it should be easier to see how to adapt it. Rick Dawson, Michael wrote: > On a recent project, I built the entire codebase using linear code > (non-OOP). It was faster for me to see what data I actually needed that > way. > > I considered this my prototype. > > Then, once I was satisfied with the project, I started to refactor my > code. I put all queries into a single CFC. I put all paper receipt > generation code into yet another CFC. > > That sure cut down on the amount of code in my main .cfm page > (controller). > > However, I noticed a few other places that could be optimized. > > So, I created a service CFC that handled all interaction between the > data CFC and the receipt CFC. The only weird part is that some of the > service CFC methods only call the database CFC methods. In fact, I used > the same method names in both CFCs. I did this because I wanted my main > ..cfm page to ONLY interact with the service CFC and not the database > CFC. > > Finally, in my main .cfm page, I was left with only a cfswitch block. > Each cfcase tag merely called on the service CFC to perform its tasks. > > This was great because I actually felt good about the code. Also, I > could fully-test each CFC and method, separately. > > Therefore, my approach was to build a low-tech prototype, then see where > I could move specific logic from the main .cfm. > > It took a couple of iterations, but it works fine and it's easy enough > to maintain. > > Mike > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314266 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: How can this CFC be improved?
Thanks for the overview, Mike. I see what everyone's saying about the encapsulation. I'm just trying to make all the pieces of the puzzle fit. Your tutorial was helpful. It was a little advanced in some respects. I just needed to approach the CFC's a little more carefully, until I could figure out what was going on, before trying to really understand the DAO approach. I'm sure to have a "eureka" moment at some point, with everyone's help..and I'm sure it'll be on a Sunday night...my "honey, don't forget to take out the garbage" night! :o) Rick Mike Kear wrote: > Rick, imagine how it would be if (as is fairly common) you have > business objects (beans) handling single items, and DAO cfcs handling > all the database interaction back and forth.This is the scenario i > drew in the tutorials I wrote ... > > So in the application scope you have a DAO - just one . sitting in > RAM waiting to be called on. And as people come and go through the > site they're causing beans to be created all over hte place to > manipulate the things they're needing as they move around. > > If (as happens frequently in one of my sites) there are 400 > concurrent users, and only one DAO for this applicatoin, imagine how > many people are likely to be simultaneously using an "Add()" method in > the DAO. In those circumstances it's absolutly essential that the > methods in teh DAO to e threadsafe. That means ALL variables inside > the methods have to be var'd unless there is a specific reason not to. > It means you have to build teh DAO carefully so data from one user > doesn't interfere with the data from the others. But that's also true > if you only have 3 simultaneous users. You still dont want their > information - maybe their shopping carts getting intermingled. > > But on the other hand if you dont have the DAO sitting in the > application scope, every time anyone uses that part of the > application, the DAO has to be instantiated again.There's an > overhead processing price to pay for doing that. > > Here's my rule of thumb. Vary away from it only once you realise > the implications ... never require a cfc to know anything about the > outside world. Anything it needs to know, you'll tell it. So > that means you tell it what the dsn is. you dont ask it to go look > in the application vars for it. You tell ilt what the different > values are for the arguments, either by passing in a struct such as > form struct or by passing in the values individually or by passing in > a bean. But the cfc doesnt have to go looking for it, and doesnt > have to know where it came from > > This is exactly how most of the built-in functions in coldfusion work. >The function replace() doesnt have to know anything - you give it > the information it needs to do its job.the replace() function > doesnt do much - it does a limited job quickly and efficiently but > its a small job.that's how to design your methods in you own cfcs > - small limited functions that dont know anything about the outside > world apart from what you tell it, and they should be threadsafe so > you dont have to use up all your ram and processing power with > bazillions of copies of the same code running at once. > > Hope this helps I rather have the feeling that at the moment > you're thinking the stuff i put in my tutorial is a lot of additional > typing - it's all too hard and too much work. That's not a problem > - it was for me too until suddenly the light went on and i had a few > of those "EUREKA!!" moments. I can disctinctly remember the day i > finally 'got it' about encapsulation.I was so excited i made the > mistake of talking about it in an agitated manner to my wife to > promptly told me to stop being so bloody stupid and put the garbage > out cos it's garbage night. > > > Cheers > Mike Kear > Windsor, NSW, Australia > Adobe Certified Advanced ColdFusion Developer > AFP Webworks > http://afpwebworks.com > ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month > > > > On Thu, Oct 23, 2008 at 3:39 AM, Rick Faircloth > <[EMAIL PROTECTED]> wrote: > >> I think I'm beginning to understand your reasoning. >> It's just taking some time for me to get to the "best practices" of CFC >> usage. >> Trying to get "anything" to work at first keeps my projects moving, while >> beginning to employ different coding techniques. I'm basically trying to >> learn by writing code for projects that are going live with these updates >> as soon as I can get them working...too busy for much practice. >> >> Also, I'm a solo developer and never plan to code while working for anyone >> else..so as far as sharing code or compensation, it doesn't matter. My >> client's >> don't care, as long as the correct data shows up on their pages. >> >> But I am trying to figure out the best way to do all of this. >> >> Thanks, >> >> Rick >> >> Dawson, Michael wrote: >> >>> Technically, they both will work. >>> >>> H
RE: How can this CFC be improved?
On a recent project, I built the entire codebase using linear code (non-OOP). It was faster for me to see what data I actually needed that way. I considered this my prototype. Then, once I was satisfied with the project, I started to refactor my code. I put all queries into a single CFC. I put all paper receipt generation code into yet another CFC. That sure cut down on the amount of code in my main .cfm page (controller). However, I noticed a few other places that could be optimized. So, I created a service CFC that handled all interaction between the data CFC and the receipt CFC. The only weird part is that some of the service CFC methods only call the database CFC methods. In fact, I used the same method names in both CFCs. I did this because I wanted my main ..cfm page to ONLY interact with the service CFC and not the database CFC. Finally, in my main .cfm page, I was left with only a cfswitch block. Each cfcase tag merely called on the service CFC to perform its tasks. This was great because I actually felt good about the code. Also, I could fully-test each CFC and method, separately. Therefore, my approach was to build a low-tech prototype, then see where I could move specific logic from the main .cfm. It took a couple of iterations, but it works fine and it's easy enough to maintain. Mike -Original Message- From: Rick Faircloth [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 22, 2008 10:39 AM To: cf-talk Subject: Re: How can this CFC be improved? I think I'm beginning to understand your reasoning. It's just taking some time for me to get to the "best practices" of CFC usage. Trying to get "anything" to work at first keeps my projects moving, while beginning to employ different coding techniques. I'm basically trying to learn by writing code for projects that are going live with these updates as soon as I can get them working...too busy for much practice. Also, I'm a solo developer and never plan to code while working for anyone else..so as far as sharing code or compensation, it doesn't matter. My client's don't care, as long as the correct data shows up on their pages. But I am trying to figure out the best way to do all of this. Thanks, Rick ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314258 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
Rick, imagine how it would be if (as is fairly common) you have business objects (beans) handling single items, and DAO cfcs handling all the database interaction back and forth.This is the scenario i drew in the tutorials I wrote ... So in the application scope you have a DAO - just one . sitting in RAM waiting to be called on. And as people come and go through the site they're causing beans to be created all over hte place to manipulate the things they're needing as they move around. If (as happens frequently in one of my sites) there are 400 concurrent users, and only one DAO for this applicatoin, imagine how many people are likely to be simultaneously using an "Add()" method in the DAO. In those circumstances it's absolutly essential that the methods in teh DAO to e threadsafe. That means ALL variables inside the methods have to be var'd unless there is a specific reason not to. It means you have to build teh DAO carefully so data from one user doesn't interfere with the data from the others. But that's also true if you only have 3 simultaneous users. You still dont want their information - maybe their shopping carts getting intermingled. But on the other hand if you dont have the DAO sitting in the application scope, every time anyone uses that part of the application, the DAO has to be instantiated again.There's an overhead processing price to pay for doing that. Here's my rule of thumb. Vary away from it only once you realise the implications ... never require a cfc to know anything about the outside world. Anything it needs to know, you'll tell it. So that means you tell it what the dsn is. you dont ask it to go look in the application vars for it. You tell ilt what the different values are for the arguments, either by passing in a struct such as form struct or by passing in the values individually or by passing in a bean. But the cfc doesnt have to go looking for it, and doesnt have to know where it came from This is exactly how most of the built-in functions in coldfusion work. The function replace() doesnt have to know anything - you give it the information it needs to do its job.the replace() function doesnt do much - it does a limited job quickly and efficiently but its a small job.that's how to design your methods in you own cfcs - small limited functions that dont know anything about the outside world apart from what you tell it, and they should be threadsafe so you dont have to use up all your ram and processing power with bazillions of copies of the same code running at once. Hope this helps I rather have the feeling that at the moment you're thinking the stuff i put in my tutorial is a lot of additional typing - it's all too hard and too much work. That's not a problem - it was for me too until suddenly the light went on and i had a few of those "EUREKA!!" moments. I can disctinctly remember the day i finally 'got it' about encapsulation.I was so excited i made the mistake of talking about it in an agitated manner to my wife to promptly told me to stop being so bloody stupid and put the garbage out cos it's garbage night. Cheers Mike Kear Windsor, NSW, Australia Adobe Certified Advanced ColdFusion Developer AFP Webworks http://afpwebworks.com ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month On Thu, Oct 23, 2008 at 3:39 AM, Rick Faircloth <[EMAIL PROTECTED]> wrote: > I think I'm beginning to understand your reasoning. > It's just taking some time for me to get to the "best practices" of CFC > usage. > Trying to get "anything" to work at first keeps my projects moving, while > beginning to employ different coding techniques. I'm basically trying to > learn by writing code for projects that are going live with these updates > as soon as I can get them working...too busy for much practice. > > Also, I'm a solo developer and never plan to code while working for anyone > else..so as far as sharing code or compensation, it doesn't matter. My > client's > don't care, as long as the correct data shows up on their pages. > > But I am trying to figure out the best way to do all of this. > > Thanks, > > Rick > > Dawson, Michael wrote: >> Technically, they both will work. >> >> However, what if you have a different process of calling the same >> function that doesn't use the form scope? >> >> What if you want to call the same method as a web service? >> >> Your current system will fail at that time. >> >> >> Of course, if you fully control your code and no one else will ever use >> it, then do what you think works best for you. >> >> I have some code that might not pass the approval of several people, but >> it works for me and I can understand it. >> >> If your code is not being compared to others, nor are you being judged >> as part of your compensation, it really doesn't matter. >> >> However, at some point, you will find that following these accepted >> principals will become beneficial. That is when
Re: How can this CFC be improved?
even if you're a solo developer, creating components that are truly "black-boxed" (e.g. they know nothing of the world outside them), you're creating components that you can potentially reuse yourself. Also, by passing in the information explicitly (rather than referring to outside scopes from within the CFC), you potentially worry less about having to refactor those CFCs. What if in the future, you're not using form variables, but you change to URL variables? The way you have it set up now, you have to make changes to the CFC. if you pass all of the variables in explicitly, it doesn't matter if you're passing form vars, URL vars, session vars, etc. your CFC is still built to work and function properly in any given environment. On Wed, Oct 22, 2008 at 8:39 AM, Rick Faircloth <[EMAIL PROTECTED]>wrote: > I think I'm beginning to understand your reasoning. > It's just taking some time for me to get to the "best practices" of CFC > usage. > Trying to get "anything" to work at first keeps my projects moving, while > beginning to employ different coding techniques. I'm basically trying to > learn by writing code for projects that are going live with these updates > as soon as I can get them working...too busy for much practice. > > Also, I'm a solo developer and never plan to code while working for anyone > else..so as far as sharing code or compensation, it doesn't matter. My > client's > don't care, as long as the correct data shows up on their pages. > > But I am trying to figure out the best way to do all of this. > > Thanks, > > Rick > > Dawson, Michael wrote: > > Technically, they both will work. > > > > However, what if you have a different process of calling the same > > function that doesn't use the form scope? > > > > What if you want to call the same method as a web service? > > > > Your current system will fail at that time. > > > > > > Of course, if you fully control your code and no one else will ever use > > it, then do what you think works best for you. > > > > I have some code that might not pass the approval of several people, but > > it works for me and I can understand it. > > > > If your code is not being compared to others, nor are you being judged > > as part of your compensation, it really doesn't matter. > > > > However, at some point, you will find that following these accepted > > principals will become beneficial. That is when it "clicks" and you see > > the light. > > > > > > > > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314239 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
> No pain no gain though, right? As long as whatever is causing the pain doesn't kill you! :o) Rick > Using CFCs as function collections like you are doing is the easy part. > Wait till you start creating a true OO backend. I'm working on my first > right now and I thought I was really good at CFCs until I started > this... No pain no gain though, right? > > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314244 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: How can this CFC be improved?
Gotcha... thanks. Charlie Griefer wrote: > even if you're a solo developer, creating components that are truly > "black-boxed" (e.g. they know nothing of the world outside them), you're > creating components that you can potentially reuse yourself. Also, by > passing in the information explicitly (rather than referring to outside > scopes from within the CFC), you potentially worry less about having to > refactor those CFCs. What if in the future, you're not using form > variables, but you change to URL variables? The way you have it set up now, > you have to make changes to the CFC. if you pass all of the variables in > explicitly, it doesn't matter if you're passing form vars, URL vars, session > vars, etc. your CFC is still built to work and function properly in any > given environment. > > On Wed, Oct 22, 2008 at 8:39 AM, Rick Faircloth <[EMAIL PROTECTED]>wrote: > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314243 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
Right!. Your call (if you are using the form scope) would look like this: object.update_product(argumentCollection=form); or object.update_product(duplicate(form)); Same thing if you are looking at something in the session: object.update_product(argumentCollection=session.key); Rick Faircloth wrote: > Thanks for the feedback, Jake. > > All that "reassigning" of variables is a lot more typing. (But, can I > get around > reassigning each form variable individually by using the > "argumentCollection" > attribute when calling the method?) > > I think I see what you're saying, however. > > By "translating" the type of variable coming in to the method into the > argument scope, > then any type of variable can be fed into the method...session, url, > form, etc.,... making > the method more flexible. > > Right? > > Thanks for the re-write, too! That helps me understand how things need > to change. > > Jake Churchill wrote: > >> I generally make my CFCs as generic as possible. You are updating a >> product and looking in the form scope for everything. It'll work, >> sure. But, what if in the future you get an entire cart. Then you >> won't be looking in the form scope, you'll be looking at something in >> the session or database. In that case, you'll want to be able to loop >> over something and pass stuff into the function which would be very >> tricky if the function is stuck in the form scope. Also, there's no >> reason to copy the arguments over to variables. Variables would be used >> more if you are actually instantiating a CFC as an object. I assume you >> are not because if you did that, you'd probably pass an object into the >> update product. >> >> Here's a way I'd re-write your function to make it more abstract: >> >> > = "Update specified product" output = "false"> >> >> >> > default=""> >> > default=""> >> >> >> > default=""> >> >> >> >> >> updateproducts >> setname = > value="#arguments.name#">, >> description = > value="#arguments.description#">, >> regular_price = > value="#arguments.regular_price#" scale="2">, >> featured = > value="#arguments.featured#">, >> special = > value="#arguments.special#">, >> special_price = > value="#arguments.special_price#" scale="2">, >> photo_150 = > value="#arguments.photo_150#">, >> photo_400 = > value="#arguments.photo_400#"> >> whereproduct_id = "#arguments.product_id#" >> >> >> >> >> -Jake Churchill >> >> Rick Faircloth wrote: >> >> >>> Hi, all... still trying to get a handle on using CFC's. >>> >>> Here's an update method I wrote and I'd like to know >>> what can be changed to make it better. Such as, >>> why not use the form scope in the query? And, why >>> not just use the application scope for the dsn, instead >>> of converting it to the variables scope? >>> >>> If components have access to the url, form, session, and >>> application scopes, etc., why not use them in the component? >>> What's the benefit of converting them? >>> >>> >> displayname="update_product" >>> hint ="Update specified product" >>> output ="false"> >>> >>> >>> >>> >>> >>> >>> updateproducts >>> >>> set name =>> cfsqltype = "cf_sql_varchar"value = "#form.name#">, >>>description=>> cfsqltype = "cf_sql_varchar"value = "#form.description#">, >>>regular_price=>> cfsqltype = "cf_sql_decimal"value = "#form.regular_price#" scale >>> = "2">, >>>featured= >>> >> "#form.featured#">, >>>special = >>> >> "#form.special#">, >>>special_price=>> cfsqltype = "cf_sql_decimal"value = "#form.special_price#" scale >>> = "2">, >>>photo_150=>> cfsqltype = "cf_sql_varchar"value = "#form.photo_150#">, >>>photo_400=>> cfsqltype = "cf_sql_varchar"value = "#form.photo_400#"> >>> >>> where product_id= >>> "#variables.product_id#" >>> >>> >>> >>> >>> >>> >>> >>> >>> >> > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http:/
Re: How can this CFC be improved?
Using CFCs as function collections like you are doing is the easy part. Wait till you start creating a true OO backend. I'm working on my first right now and I thought I was really good at CFCs until I started this... No pain no gain though, right? Rick Faircloth wrote: > Good...maybe I'll catch on before the next decade rolls around... > > > Jake Churchill wrote: > >> Right!. >> >> Your call (if you are using the form scope) would look like this: >> >> object.update_product(argumentCollection=form); >> or >> object.update_product(duplicate(form)); >> >> Same thing if you are looking at something in the session: >> object.update_product(argumentCollection=session.key); >> >> >> >> > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314240 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: How can this CFC be improved?
Good...maybe I'll catch on before the next decade rolls around... Jake Churchill wrote: > Right!. > > Your call (if you are using the form scope) would look like this: > > object.update_product(argumentCollection=form); > or > object.update_product(duplicate(form)); > > Same thing if you are looking at something in the session: > object.update_product(argumentCollection=session.key); > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314237 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
I think I'm beginning to understand your reasoning. It's just taking some time for me to get to the "best practices" of CFC usage. Trying to get "anything" to work at first keeps my projects moving, while beginning to employ different coding techniques. I'm basically trying to learn by writing code for projects that are going live with these updates as soon as I can get them working...too busy for much practice. Also, I'm a solo developer and never plan to code while working for anyone else..so as far as sharing code or compensation, it doesn't matter. My client's don't care, as long as the correct data shows up on their pages. But I am trying to figure out the best way to do all of this. Thanks, Rick Dawson, Michael wrote: > Technically, they both will work. > > However, what if you have a different process of calling the same > function that doesn't use the form scope? > > What if you want to call the same method as a web service? > > Your current system will fail at that time. > > > Of course, if you fully control your code and no one else will ever use > it, then do what you think works best for you. > > I have some code that might not pass the approval of several people, but > it works for me and I can understand it. > > If your code is not being compared to others, nor are you being judged > as part of your compensation, it really doesn't matter. > > However, at some point, you will find that following these accepted > principals will become beneficial. That is when it "clicks" and you see > the light. > > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314236 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: How can this CFC be improved?
Correct. -Original Message- From: Rick Faircloth [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 22, 2008 10:19 AM To: cf-talk Subject: Re: How can this CFC be improved? > the lifetime of the component's instance Such as, if the variable is going to be used in other methods before returning data to the calling page? Dawson, Michael wrote: > Couple others suggestions... > > You need to VAR your query: > > In your cffunction tag right after the cfargument tag, add: > > > > Also, Lose the " and # characters: > > > > (However, you don't really need to set this variable unless you need > to store the product_id for the lifetime of the component's instance.) > > mike ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314233 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: How can this CFC be improved?
Technically, they both will work. However, what if you have a different process of calling the same function that doesn't use the form scope? What if you want to call the same method as a web service? Your current system will fail at that time. Of course, if you fully control your code and no one else will ever use it, then do what you think works best for you. I have some code that might not pass the approval of several people, but it works for me and I can understand it. If your code is not being compared to others, nor are you being judged as part of your compensation, it really doesn't matter. However, at some point, you will find that following these accepted principals will become beneficial. That is when it "clicks" and you see the light. -Original Message- From: Rick Faircloth [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 22, 2008 10:15 AM To: cf-talk Subject: Re: How can this CFC be improved? Thanks for the feedback, Mike. > Even though it works, it is not a normal practice for the guts of a > component to know what is going on outside. What's the difference, ultimately, in referring to the form variables in and just referring to them directly in the query? Either way, they're still just methods of "informing" the method of the data "on the outside", right??? It just seems like two different ways of doing the same thing... Rick ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314232 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: How can this CFC be improved?
Thanks for the feedback, Jake. All that "reassigning" of variables is a lot more typing. (But, can I get around reassigning each form variable individually by using the "argumentCollection" attribute when calling the method?) I think I see what you're saying, however. By "translating" the type of variable coming in to the method into the argument scope, then any type of variable can be fed into the method...session, url, form, etc.,... making the method more flexible. Right? Thanks for the re-write, too! That helps me understand how things need to change. Jake Churchill wrote: > I generally make my CFCs as generic as possible. You are updating a > product and looking in the form scope for everything. It'll work, > sure. But, what if in the future you get an entire cart. Then you > won't be looking in the form scope, you'll be looking at something in > the session or database. In that case, you'll want to be able to loop > over something and pass stuff into the function which would be very > tricky if the function is stuck in the form scope. Also, there's no > reason to copy the arguments over to variables. Variables would be used > more if you are actually instantiating a CFC as an object. I assume you > are not because if you did that, you'd probably pass an object into the > update product. > > Here's a way I'd re-write your function to make it more abstract: > > = "Update specified product" output = "false"> > > > default=""> > default=""> > > > default=""> > > > > > updateproducts > setname = value="#arguments.name#">, > description = value="#arguments.description#">, > regular_price = value="#arguments.regular_price#" scale="2">, > featured = value="#arguments.featured#">, > special = value="#arguments.special#">, > special_price = value="#arguments.special_price#" scale="2">, > photo_150 = value="#arguments.photo_150#">, > photo_400 = value="#arguments.photo_400#"> > whereproduct_id = "#arguments.product_id#" > > > > > -Jake Churchill > > Rick Faircloth wrote: > >> Hi, all... still trying to get a handle on using CFC's. >> >> Here's an update method I wrote and I'd like to know >> what can be changed to make it better. Such as, >> why not use the form scope in the query? And, why >> not just use the application scope for the dsn, instead >> of converting it to the variables scope? >> >> If components have access to the url, form, session, and >> application scopes, etc., why not use them in the component? >> What's the benefit of converting them? >> >> > displayname="update_product" >> hint ="Update specified product" >> output ="false"> >> >> >> >> >> >> >> updateproducts >> >> set name => cfsqltype = "cf_sql_varchar"value = "#form.name#">, >>description=> cfsqltype = "cf_sql_varchar"value = "#form.description#">, >>regular_price=> cfsqltype = "cf_sql_decimal"value = "#form.regular_price#" scale >> = "2">, >>featured= >> > "#form.featured#">, >>special = >> > "#form.special#">, >>special_price=> cfsqltype = "cf_sql_decimal"value = "#form.special_price#" scale >> = "2">, >>photo_150=> cfsqltype = "cf_sql_varchar"value = "#form.photo_150#">, >>photo_400=> cfsqltype = "cf_sql_varchar"value = "#form.photo_400#"> >> >> where product_id= >> "#variables.product_id#" >> >> >> >> >> >> >> >> > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314231 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: How can this CFC be improved?
But by referring to the form directly, your CFC already knows about the outside. I am just learning about CFCs and OO myself, but I thought the point of them was to make them independent of what was going on the outside, and to just pass them the information that they needed regardless of the source. Meaning, that perhaps your CFC requires another method that is getSource so that you could pass it a var that sets the source to a struct that contains form data, or a struct that contains data not from a form, or to use a query result from the DB. Rob On Wed, Oct 22, 2008 at 11:14 AM, Rick Faircloth <[EMAIL PROTECTED]>wrote: > Thanks for the feedback, Mike. > > > Even though it works, it is not a normal practice for the guts of a > > component to know what is going on outside. > > What's the difference, ultimately, in referring to the form variables > in and just referring > to them directly in the query? > > Either way, they're still just methods of "informing" the method of > the data "on the outside", right??? > > It just seems like two different ways of doing the same thing... > > Rick > > Dawson, Michael wrote: > > Even though it works, it is not a normal practice for the guts of a > > component to know what is going on outside. > > > > Alghouth it's a reach, it is possible that your update_product method > > could accept URL variables, rather than form variables. If this were > > true, then you would have to modify your method. > > > > However, if you called the update_product method, and passed in the form > > scope, you would not have to change your method. > > > > For example: > > > > > > > > > > > > > > > > > > > > > > Could easily be changed to: > > > > > > > > without having to touch your update_product method. > > > > Like I said, even though it works, most people try to avoid referencing > > external scopes outside the component. The worst-case scenario would be > > that you may be put on someone's do-not-hire list because they are > > sticklers for things such as this. ;^) > > > > Mike > > > > -Original Message- > > From: Rick Faircloth [mailto:[EMAIL PROTECTED] > > Sent: Wednesday, October 22, 2008 9:10 AM > > To: cf-talk > > Subject: How can this CFC be improved? > > > > Hi, all... still trying to get a handle on using CFC's. > > > > Here's an update method I wrote and I'd like to know what can be changed > > to make it better. Such as, why not use the form scope in the query? > > And, why not just use the application scope for the dsn, instead of > > converting it to the variables scope? > > > > If components have access to the url, form, session, and application > > scopes, etc., why not use them in the component? > > What's the benefit of converting them? > > > > > > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314230 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
> the lifetime of the component's instance Such as, if the variable is going to be used in other methods before returning data to the calling page? Dawson, Michael wrote: > Couple others suggestions... > > You need to VAR your query: > > In your cffunction tag right after the cfargument tag, add: > > > > Also, Lose the " and # characters: > > > > (However, you don't really need to set this variable unless you need to > store the product_id for the lifetime of the component's instance.) > > mike > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314229 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
Thanks for the feedback, Mike. > Even though it works, it is not a normal practice for the guts of a > component to know what is going on outside. What's the difference, ultimately, in referring to the form variables in and just referring to them directly in the query? Either way, they're still just methods of "informing" the method of the data "on the outside", right??? It just seems like two different ways of doing the same thing... Rick Dawson, Michael wrote: > Even though it works, it is not a normal practice for the guts of a > component to know what is going on outside. > > Alghouth it's a reach, it is possible that your update_product method > could accept URL variables, rather than form variables. If this were > true, then you would have to modify your method. > > However, if you called the update_product method, and passed in the form > scope, you would not have to change your method. > > For example: > > > > > > > > > > > Could easily be changed to: > > > > without having to touch your update_product method. > > Like I said, even though it works, most people try to avoid referencing > external scopes outside the component. The worst-case scenario would be > that you may be put on someone's do-not-hire list because they are > sticklers for things such as this. ;^) > > Mike > > -Original Message- > From: Rick Faircloth [mailto:[EMAIL PROTECTED] > Sent: Wednesday, October 22, 2008 9:10 AM > To: cf-talk > Subject: How can this CFC be improved? > > Hi, all... still trying to get a handle on using CFC's. > > Here's an update method I wrote and I'd like to know what can be changed > to make it better. Such as, why not use the form scope in the query? > And, why not just use the application scope for the dsn, instead of > converting it to the variables scope? > > If components have access to the url, form, session, and application > scopes, etc., why not use them in the component? > What's the benefit of converting them? > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314227 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: How can this CFC be improved?
> -Original Message- > From: Rick Faircloth [mailto:[EMAIL PROTECTED] > Sent: Wednesday, October 22, 2008 10:10 AM > To: cf-talk > Subject: How can this CFC be improved? > > Hi, all... still trying to get a handle on using CFC's. > > Here's an update method I wrote and I'd like to know > what can be changed to make it better. Such as, > why not use the form scope in the query? And, why > not just use the application scope for the dsn, instead > of converting it to the variables scope? I don't see anything "wrong" with that per se. However I've sometimes found it more versatile to parametize such things: in the best case you'll be using your CFCs again in other sites (portability of OO) and knowing what they need and being able to control it without modifying the CFC is sometimes a life-saver. > If components have access to the url, form, session, and > application scopes, etc., why not use them in the component? > What's the benefit of converting them? In general OO "likes" to be encapsulated - the information used by an object should be clearly passed in and out. Of course there are millions of exceptions, but that's the rule of thumb. One comment at least in this code: it seems like you're creating the query in the CFC variables scope (by not creating the query name first with "var"). This makes it available outside of the CFC but also makes the CFC less self-documenting. As with the input side being explicit about the output side is also generally desirable: in this case making the query variable a function-local variable (using "var") and passing the result explicitly out using "return". More importantly however: this could cause data corruption depending on how you instantiate this CFC. For example if you make this CFC persistent (store it in the Session, Application or Server scopes) you might get a situation where two requests call the same method. If that happens the methods themselves will be isolated but the "public" variable they BOTH write too is not. If they both run at the same time you could very easily end up with data from one thread ending up in the other. Not good. Jim Davis ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314225 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: How can this CFC be improved?
I generally make my CFCs as generic as possible. You are updating a product and looking in the form scope for everything. It'll work, sure. But, what if in the future you get an entire cart. Then you won't be looking in the form scope, you'll be looking at something in the session or database. In that case, you'll want to be able to loop over something and pass stuff into the function which would be very tricky if the function is stuck in the form scope. Also, there's no reason to copy the arguments over to variables. Variables would be used more if you are actually instantiating a CFC as an object. I assume you are not because if you did that, you'd probably pass an object into the update product. Here's a way I'd re-write your function to make it more abstract: updateproducts setname = , description = , regular_price = , featured = , special = , special_price = , photo_150 = , photo_400 = whereproduct_id = "#arguments.product_id#" -Jake Churchill Rick Faircloth wrote: > Hi, all... still trying to get a handle on using CFC's. > > Here's an update method I wrote and I'd like to know > what can be changed to make it better. Such as, > why not use the form scope in the query? And, why > not just use the application scope for the dsn, instead > of converting it to the variables scope? > > If components have access to the url, form, session, and > application scopes, etc., why not use them in the component? > What's the benefit of converting them? > > displayname="update_product" > hint ="Update specified product" > output ="false"> > > > > > > > updateproducts > > set name = cfsqltype = "cf_sql_varchar"value = "#form.name#">, >description= cfsqltype = "cf_sql_varchar"value = "#form.description#">, >regular_price= cfsqltype = "cf_sql_decimal"value = "#form.regular_price#" scale > = "2">, >featured= > "#form.featured#">, >special = > "#form.special#">, >special_price= cfsqltype = "cf_sql_decimal"value = "#form.special_price#" scale > = "2">, >photo_150= cfsqltype = "cf_sql_varchar"value = "#form.photo_150#">, >photo_400= cfsqltype = "cf_sql_varchar"value = "#form.photo_400#"> > > where product_id= > "#variables.product_id#" > > > > > > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314220 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: How can this CFC be improved?
Couple others suggestions... You need to VAR your query: In your cffunction tag right after the cfargument tag, add: Also, Lose the " and # characters: (However, you don't really need to set this variable unless you need to store the product_id for the lifetime of the component's instance.) mike -Original Message- From: Rick Faircloth [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 22, 2008 9:10 AM To: cf-talk Subject: How can this CFC be improved? Hi, all... still trying to get a handle on using CFC's. Here's an update method I wrote and I'd like to know what can be changed to make it better. Such as, why not use the form scope in the query? And, why not just use the application scope for the dsn, instead of converting it to the variables scope? If components have access to the url, form, session, and application scopes, etc., why not use them in the component? What's the benefit of converting them? updateproducts ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314219 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: How can this CFC be improved?
Even though it works, it is not a normal practice for the guts of a component to know what is going on outside. Alghouth it's a reach, it is possible that your update_product method could accept URL variables, rather than form variables. If this were true, then you would have to modify your method. However, if you called the update_product method, and passed in the form scope, you would not have to change your method. For example: Could easily be changed to: without having to touch your update_product method. Like I said, even though it works, most people try to avoid referencing external scopes outside the component. The worst-case scenario would be that you may be put on someone's do-not-hire list because they are sticklers for things such as this. ;^) Mike -Original Message- From: Rick Faircloth [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 22, 2008 9:10 AM To: cf-talk Subject: How can this CFC be improved? Hi, all... still trying to get a handle on using CFC's. Here's an update method I wrote and I'd like to know what can be changed to make it better. Such as, why not use the form scope in the query? And, why not just use the application scope for the dsn, instead of converting it to the variables scope? If components have access to the url, form, session, and application scopes, etc., why not use them in the component? What's the benefit of converting them? ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314217 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4