> -----Original Message-----
> From: Ben Rogers [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, December 29, 2004 10:04 AM
> To: CF-Talk
> Subject: RE: My Init() in my CFC...am I on the right track?
>
> I agree. I was only referring to setter methods (though I may not have
> been
> very clear about that). In the above example, you're using getters. A
> getter's purpose is to return something. Conseqently, the purpose of the
> line above seems very clear to me.
> 
> This is in contrast to an example posted by Sean in another thread:
> 
>   person.setFirstName("Sean").setLastName("Corfield")
> 
> I find it more difficult to read. I would be very surprised if it were any
> faster than two lines of code. So, I was wondering if there were any other
> benefits or tricks that I'm missing.

No, I agree first!  ;^)

I've heard one argument with setters in that it might allow for more
structured sets of complex data to be read more easily.  For example if you
have a form accepting first, middle and last names you could say:

person.setFirstName("Sean").setMiddleName("Elizabeth").setLastName("Corfield
")

(I am, however, guessing on the actual middle name in this case.)

In this case I can see the argument that when you put on "syntax blinders"
you see the name of the person as it should be seen.  However I agree that
the following seems much more readable:

person.setFirstName("Sean")
person.setMiddleName("Elizabeth")
person.setLastName("Corfield")

The other argument I've read is when you use a setter for an object, then
immediately grab something from that object.  Something like:

profile.setPerson(Sean).getFirstName()

I see this as a little more useful than the first argument (which to me is
really simplistic and should be multiple lines).  At the same time cases
like this seem pretty rare to me.

I've also heard (what I consider completely asinine) arguments that "smaller
code is better" or "runs faster" or whatever.  This of course is complete
bullshit (it was bullshit even in the old CF days when the language was
tokenized and is even moreso now in the compiled Java world).

Still - returning "this" in a setter doesn't force you use this, it just
provides the potential.

Jim Davis





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Silver Sponsor - CFDynamics
http://www.cfdynamics.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188931
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to