re: CFC's.. Why use them?

2009-09-08 Thread Jason Fisher

Just a quick thought:  If, for example, you are building reusable, 
singleton components (sorry for the OO buzzwords, but it is descriptive 
terminology), then you can load those CFCs into Application scope and have 
them exist in memory only once but still be used across all requests in the 
app.  An include, by contrast, has to be rendered anew each time the outer 
template is called.  In other words, using components makes it easier to 
encapsulate functionality, but there is otherwise little *functional* 
difference.
 


~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326087
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: CFC's.. Why use them?

2009-09-08 Thread Phillip Vector

Gotcha. Thanks. :)

On Tue, Sep 8, 2009 at 7:49 AM, Jason Fisherja...@wanax.com wrote:

 Just a quick thought:  If, for example, you are building reusable,
 singleton components (sorry for the OO buzzwords, but it is descriptive
 terminology), then you can load those CFCs into Application scope and have
 them exist in memory only once but still be used across all requests in the
 app.  An include, by contrast, has to be rendered anew each time the outer
 template is called.  In other words, using components makes it easier to
 encapsulate functionality, but there is otherwise little *functional*
 difference.



 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326088
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


RE: CFC's.. Why use them?

2009-09-08 Thread brad

I'd sure hate to write a SOAP webservice in a .cfm file.  

Also, cfm files don't give you objects that can be passed around,
provide encapsulation of data, and support code re-use via inheritance
and method overriding.  I mean, you can do anything you want in cfm
files, but there are some things that are just way cleaner and easier in
a component if you want to drink the koolaid and change your paradigm. 
CFCs can be used as glorified include files with no ill side affects,
but if that is all you are doing with them it's kind of like starting
your microwave on fire to cook your supper over it. :)
~Brad

 Original Message 
 Subject: CFC's.. Why use them?
 From: Phillip Vector vec...@mostdeadlygame.com
 Date: Tue, September 08, 2009 9:39 am
 To: cf-talk cf-talk@houseoffusion.com
 
 
 Besides the code being reusable, is there a specific reason why I
 should use a CFC rather then a CFM file?
 


~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326093
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


RE: CFC's.. Why use them?

2009-09-08 Thread Jason Fisher

like starting your microwave on fire to cook your supper over it

That is a wonderfully expressive metaphor (and accurate to the example, 
too!)
 


~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326094
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: CFC's.. Why use them?

2009-09-08 Thread Peter Boughton

Just a quick thought:  If, for example, you are building reusable, 
singleton components (sorry for the OO buzzwords, but it is descriptive 
terminology), then you can load those CFCs into Application scope and have 
them exist in memory only once but still be used across all requests in the 
app.

Putting a CFC in the Application scope is *NOT* creating a Singleton.

A CFC in the Application scope is an instance of that object, but there is 
nothing stopping you creating multiple instances of that CFC - whether still in 
the Application scope or other scopes.

A Singleton is an object that *can only have one instance*, returning that same 
instance even if you try to create a new instance.

And, particularly with OO, the times when you actually want an enforced single 
instance are rare - so if someone starts talking about Singletons, there's a 
good chance they've misunderstand OO's concepts. 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326096
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


Re: CFC's.. Why use them?

2009-09-08 Thread Nathan Strutz

Brad, I love the microwave analogy.

Phillip, CFCs as a fancy include tends to be the first step on your way to
really understanding components and objects. I've been with a few groups who
have gone (and taken me) through the course. The evolution is like this:

---
CFC as a function utility library. Functions are a small piece of reusable
code, putting them together makes sense.

Put that util.cfc in the application scope, seems to make it faster. (now
it's a singleton)

CFC as a place to put your queries. Moves them out of separate files or the
top of your cfm pages. Some get stuck here because this is the least
reusable stage. This is not OO and makes working with CFCs very
uncomfortable.

CFC as the action back-end (the model) to an area of your application.
Similar to the above, but may have more processing, and some functions
without any queries.

CFC as a black-box to a specific concept in your application. Finally a real
object with properties and methods. Now, finally, you have an object that
can be reused. This step usually comes out of need for something that has to
be used in multiple apps or laziness (in a good way), not wanting to re-type
boilerplate stuff like a user/login system.

And finally, eventually, an actual model, with more objects and some actual
layers of objects. Here, you will recognize larger pieces of your
application that can be reused, not just single CFCs.
---

This is not to say that everybody will do this, everyone's experiences are
different, but it's just a pattern I've seen.

nathan strutz
[Blog and Family @ http://www.dopefly.com/]
[AZCFUG Manager @ http://www.azcfug.org/]
[Twitter @nathanstrutz]


On Tue, Sep 8, 2009 at 10:47 AM, b...@bradwood.com wrote:


 I'd sure hate to write a SOAP webservice in a .cfm file.

 Also, cfm files don't give you objects that can be passed around,
 provide encapsulation of data, and support code re-use via inheritance
 and method overriding.  I mean, you can do anything you want in cfm
 files, but there are some things that are just way cleaner and easier in
 a component if you want to drink the koolaid and change your paradigm.
 CFCs can be used as glorified include files with no ill side affects,
 but if that is all you are doing with them it's kind of like starting
 your microwave on fire to cook your supper over it. :)
 ~Brad

  Original Message 
  Subject: CFC's.. Why use them?
  From: Phillip Vector vec...@mostdeadlygame.com
  Date: Tue, September 08, 2009 9:39 am
  To: cf-talk cf-talk@houseoffusion.com


  Besides the code being reusable, is there a specific reason why I
  should use a CFC rather then a CFM file?



 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326098
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: CFC's.. Why use them?

2009-09-08 Thread Nathan Strutz

Peter,

I understand the singleton pattern. It's lovely, on a cloudy day or sipping
some tea or whatever, but in CF, don't you think that implementing the true
singleton pattern is overkill and generally unnecessary? Consider our lack
of true constructors, the stateless nature of the web, and multiple server
configurations that many of us use. Honestly, I'm just interested in your
opinion.

Or, are you just saying we throw the word around like candy at a parade and
should stop before we hit someone in the eye? What then should we call it?

nathan strutz
[Blog and Family @ http://www.dopefly.com/]
[AZCFUG Manager @ http://www.azcfug.org/]
[Twitter @nathanstrutz]


On Tue, Sep 8, 2009 at 10:59 AM, Peter Boughton bought...@gmail.com wrote:


 Just a quick thought:  If, for example, you are building reusable,
 singleton components (sorry for the OO buzzwords, but it is descriptive
 terminology), then you can load those CFCs into Application scope and have
 them exist in memory only once but still be used across all requests in
 the
 app.

 Putting a CFC in the Application scope is *NOT* creating a Singleton.

 A CFC in the Application scope is an instance of that object, but there is
 nothing stopping you creating multiple instances of that CFC - whether still
 in the Application scope or other scopes.

 A Singleton is an object that *can only have one instance*, returning that
 same instance even if you try to create a new instance.

 And, particularly with OO, the times when you actually want an enforced
 single instance are rare - so if someone starts talking about Singletons,
 there's a good chance they've misunderstand OO's concepts.




~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326099
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: CFC's.. Why use them?

2009-09-08 Thread Phillip Vector

Thanks for the replies guys. I have currently the task of converting
over a straight forward web app to fusebox. The app already has allot
of repeat code and this isn't something that is going to be easy at
all.

One thing I have going on is that I have LOTS of cfcs. I mean, LOTS of
them (over 100). I was hoping to move them into basic action files and
query files for ease of viewing and working on. That's the main drive
of converting to fusebox in the first place. So we can have all the
code there to see. Repeating the code isn't an issue as long as it can
be divided out so if one person messes up the cfc in the accounting
circuit, it won't mess things up in ordering and such.

I was just wondering if the site will take a major performance hit if
I change it from individual files to cfcs or visa versa.

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326101
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: CFC's.. Why use them?

2009-09-08 Thread Peter Boughton

Hi Nathan,

Yes, this bit:
Or, are you just saying we throw the word around like candy at a parade and
should stop before we hit someone in the eye?

Though this one is not just the CF community - plenty of people all round don't 
really know what Singletons (and even design patterns in general) actually are.

People shouldn't use terms they don't understand!
(By which I don't mean that they need in-depth knowledge, but they should go 
check an authoritative definition first, so they at least know what they're 
actually saying.)


What then should we call it?

A component instance in the application scope?

That would do, or global object(s) for something shorter.

Could even go with glob(s) I guess - although not sure on that one.

Heh. Turns out glob is already taken, as the verb for using filename 
wildcards. :/


Oh, and for this bit:

but in CF, don't you think that implementing the true
singleton pattern is overkill and generally unnecessary?

Yep - and I wouldn't restrict to CF either; I've never found/thought of a place 
where it's necessary to have only a single instance of an object. I suspect 
there are some out there, but I can't come up with anything I don't then change 
my mind on.

Also, beyond programming even, it's really irritating having apps that force a 
single instance on you (*growls at firefox*) for no valid reason.


~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326115
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


RE: CFC's.. Why use them?

2009-09-08 Thread Scott Stewart

Phillip,

One of the things that CFC's can do is encapsulate repetitive code, you can
write a function one time and call it multiple times.

One of the other big things is that CFC's and OO in general, allow you to
build apps that are more easily scaled...

It sounds like CFC's aren't the issue but the improper use thereof

Check out Dan Wilson's blog for some great refactoring tutorials

http://www.nodans.com/page.cfm/Tutorials


--
Scott Stewart
ColdFusion Developer
4405 Oakshyre Way
Raleigh, NC 27616
(h) 919.874.6229 (c) 703.220.2835
-Original Message-
From: Phillip Vector [mailto:vec...@mostdeadlygame.com] 
Sent: Tuesday, September 08, 2009 2:35 PM
To: cf-talk
Subject: Re: CFC's.. Why use them?


Thanks for the replies guys. I have currently the task of converting
over a straight forward web app to fusebox. The app already has allot
of repeat code and this isn't something that is going to be easy at
all.

One thing I have going on is that I have LOTS of cfcs. I mean, LOTS of
them (over 100). I was hoping to move them into basic action files and
query files for ease of viewing and working on. That's the main drive
of converting to fusebox in the first place. So we can have all the
code there to see. Repeating the code isn't an issue as long as it can
be divided out so if one person messes up the cfc in the accounting
circuit, it won't mess things up in ordering and such.

I was just wondering if the site will take a major performance hit if
I change it from individual files to cfcs or visa versa.



~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326113
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: CFC's.. Why use them?

2009-09-08 Thread Sean Corfield

On Tue, Sep 8, 2009 at 1:38 PM, Peter Boughtonbought...@gmail.com wrote:
 Though this one is not just the CF community - plenty of people all round 
 don't really know what Singletons (and even design patterns in general) 
 actually are.

Remember that Singleton is a DESIGN pattern. The complexities we see
in much of the published literature are based on Java's inability to
cleanly implement a secure Singleton design because it doesn't have a
global scope and any real sense of application startup. Don't mix
design and implementation.

For CFML, we have application startup where we can create our one
instance and we have application scope where we can make that one
instance available everywhere.

For any language that has a global scope and a well-defined
application entry point, implementing the Singleton DESIGN pattern is
pretty much trivial.

Implementing a design pattern doesn't have to be complicated if your
language provides a clean way to do it.

If you're fussy about encapsulating the single instance in a method
call in CFML, just add an instance() method that returns
application.theSingleton - but this is already overly complex and
unnecessary in my mind, forcing you to trade off some of the
high-level simplicities CFML brings to the table in exchange for a
purity that adds no value.
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

If you're not annoying somebody, you're not really alive.
-- Margaret Atwood

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326117
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


Re: CFC's.. Why use them?

2009-09-08 Thread Gerald Guido

I think that one of the best uses of CFC's (and UDFs and custom tags) is to
abstract or hide a lot of  code behind simple function calls or custom
tags so you can make changes in one place and have of in effect globally. Or
if you abstract part of your code, like the database layer, you can make
(some times drastic) changes and have the rest of the app go uneffected by
the change.

Take a database abstraction layer (like Steve Bryant's DataMgr) as an
example. In your standard CWACK CFM page/Action page paradigm let's say that
your action pages have INSERT, UPDATE and DELETE queries coded on a CFM
page (or several pages) and you make CRUD calls to the database in four or
five places in your app; You have the option (for the purpose of example and
not best practices) of pointing your form or list pages at the page(s) that
contain the queries, or including the page(s), or copy and pasting the
queries to several pages in your site. Now if you make changes to your
database (and you will more often than not) you have to make changes to all
of those queries and/or pages.

Now if you abstracted your database layer using CFC's you only need to make
changes in one place (I guess that is code reuse).

So with DataMgr (or any other Database abstraction layer) you are just
making function calls to a CFC's like so:
cfset employee_id = Application.DataMgr.saveRecord(employees,Form)

Now you can make tons of changes to your database and you don't have to make
changes to any of your (simple) CRUD queries. DataMgr creates the queries on
the fly so that may not be a good example. But even with Transfer all you
need to do is regenerate the code created by Transfer with the new database
structure. Your view pages (read: cfm's) are totally agnostic to, and knows
nothing of, the database. You can swap out database engines or even rewrite
the function calls to use web services to update your data and it will have
little or no effect on your views (in theory that it, it is seldom that
easy).

Or say you find a bug in a function or chunk of code that you have copy and
pasted all over the place, you have to make changes to each one of those
chunks of code.

Here is another example but it  takes the form of a custom tag (but the
concept is the same). We used to use Googie spell as the spell checker on
our intranet (this predated my employment btw). There were a couple of
hundred instances of the spell checker strewn about the intranet and all of
them were copy and pasted in there. One day Googie spell stopped working for
some reason (I forget why).

Now we had to update several hundred chunks of code to change. What a
nightmare. When we settled on a new spell checker I wrapped inside a custom
tag. We still had to update a bazillion instances of the old spell checker.
But now we can change the functionality of it or even swap it out for
another spell check engine and all I need to do is change one or two files
and the changes are global.

As Forrest Gump put it ...that's good! One less thing.

G!



On Tue, Sep 8, 2009 at 10:39 AM, Phillip Vector
vec...@mostdeadlygame.comwrote:


 Besides the code being reusable, is there a specific reason why I
 should use a CFC rather then a CFM file?

 I mean, from what I understand about CFC's, they use the same
 processing power as a file cfincluded. Am I incorrect in this? Is
 there a compelling reason to use CFCs instead of normal code?

 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326122
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: CFC's.. Why use them?

2009-09-08 Thread Casey Dougall

On Tue, Sep 8, 2009 at 4:39 PM, Scott Stewart sstwebwo...@bellsouth.netwrote:


 Phillip,

 One of the things that CFC's can do is encapsulate repetitive code, you can
 write a function one time and call it multiple times.



I personally like knowing what I actually send to a cfc. With an include and
the variables you have floating around your application it may leads to more
mistakes. Even a secondary cfoutput tag can cause issues in an include file.
With a cfc you know what you are sending. You need to send, abc and expect
xyz back regardless of where you call it from.


~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326123
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: CFC's.. Why use them?

2009-09-08 Thread s. isaac dealey

 Remember that Singleton is a DESIGN pattern. The complexities we see
 in much of the published literature are based on Java's inability to
 cleanly implement a secure Singleton design because it doesn't have a
 global scope and any real sense of application startup. Don't mix
 design and implementation.
...
 If you're fussy about encapsulating the single instance in a method
 call in CFML, just add an instance() method that returns
 application.theSingleton - but this is already overly complex and
 unnecessary in my mind, forcing you to trade off some of the
 high-level simplicities CFML brings to the table in exchange for a
 purity that adds no value.

I'm not sure I would say it adds no value. I think it depends on the
goal of the project. I'm working on a project right now that does
essentially this, except it's returned from init(), not from a separate
instance() method. The reason in my case is to eliminate a dependency,
making the project an optional / scaling addition, rather than a
prerequisite. Figuring out how to put a singleton into Railo's cluster
scope was kind of interesting too. ;) 

-- 
s. isaac dealey  ^  new epoch
 isn't it time for a change? 
 ph: 817.385.0301

http://onTap.riaforge.org/blog



~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326121
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4