Title: [CFCDev] "this" scope vs. unnamed
My biggest concern with not using this is that you lose the ability to validate as an object type (which we are doing now).  Such as if you set a function argument to a type="your specific object"  and are not using the this scope you get an error (and rightfully so).  Have you found a way around this, other then creating dummy values in the this scope for validation?
 
 
 
 
----- Original Message -----
Sent: Wednesday, July 30, 2003 4:09 PM
Subject: RE: [CFCDev] "this" scope vs. unnamed

Here's the difference:
 
"THIS" is, as far as I can tell, a reference to the public scope of a CFC instance.

The "Unnamed" scope is equivalent to the "Variables" scope in all other CFM pages (in fact, in RedSky Variables will be fixed to allow its use in the same way in CFCs [this is public info now, right?]).  It is "private" to a given instance of the CFC.  (It is not truly "private" in the java sense of the word, but there's no reason to confuse matters with that discussion here.)
 
Personally, I have not yet found a time when you'd say "this.firstName".  I subscribe to the notion that instance data should be private and accessed via methods rather than exposed directly -- if you want to say myComponentInstance.firstName then why not just use a structure?  Also, see my previous post for some of the reasons it's a "good thing" to not expose your instance data directly.
 
As for this.methodName() -- the only time I can imagine that is necessary is if you have two methods with the same name, one is private and the other is public (which, last I checked, was allowed by the compiler -- though, it might not be any more).  But, personally that sounds like a bad idea in the first place -- I have never found a need to say this.methodName() as opposed to just methodName().
 
Now, I am not alone in opposing the use of "this", but I am also not speaking for everyone.  In fact, the official documentation about CFCs shows using "this" for your instance data.  Several articles I've seen written about CFCs show using "this".  I'm not as religious as some about preserving the object metaphor and strict encapsulation, but I don't think you can go wrong by sticking with private data instead of using THIS.
 
HTH.
 
 - Nathan
 
 
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Davis, Eric
Sent: Wednesday, July 30, 2003 12:53 PM
To: '[EMAIL PROTECTED]'
Subject: [CFCDev] "this" scope vs. unnamed

(comments, conversation interspersed)

| > Sparrow-Hood, Walter:
| >
| > First of all I'd like to thank the regular contributors to this
| > list.  I've been monitoring the discussions for the last
| > month or two and it has been extremely useful for someone
| > like me who is struggling to use CFCs correctly but who
| > doesn't have a background in Java or OOP


I'll echo that statement very loudly. Thanks for all the help you've given me, folks, whether or not you've known you've been.

| Nathan Dintenfass:
|
| ...if you want to be formal about it, you shouldn't even have a publicly
| accessible property called "name" (and you avoid that by NOT using "this"
| for your instance data -- instead use the unnamed scope [some use a
| "virtual" scope, as discussed in previous posts]).


What I can't really understand at this point is the difference between the "this" scope and the unnamed-scope-that-really-isn't-a-scope (or a virtual "instance" scope). When would it ever make sense to use this.propertyName? How about invoking other methods of the same component: this.myOtherMethod() or just myOtherMethod() ?

Or is the answer to this question so preference-based that either it isn't possible to choose a way, or it doesn't matter if you do choose, except in the case of internal standards?

Thanks again, all.

--
Eric C. Davis

Reply via email to