Hi Ryan,

After going around in circles for a long time on this, i've come down to a preference to not use typing in CF, but i still see the usefulness of it. So if i'm working with someone who wants to use typing in their CFC's, i'm gonna say "Sure, let's do that!" rather than risk losing the work.

Rather than repeat my long-winded self, i'll just throw a link here:

http://aria-media.com/blog/index.cfm/2006/10/6/To-Type-or-Not-to-Type

If you're working in a team, maybe a large one, on a big project ... well, typing or some other convention (in the hint tag for instance) to document what your methods expect and return is going to be really helpful. Even if you're working by yourself, it can be helpful. But it can also get in the way, because CF is loosely typed. And i believe that makes sense, because there is no such thing as type on the web. All you've got are strings being passed back and forth from web forms and the like.

The transfer framework is in fact typed. Mark Mandel comes from a Java background so he probably will leave it that way, at least for awhile. MG and Reactor aren't, but that doesn't mean you can't run into "typing problems" with the extends attribute in those frameworks if you try, especially on Linux. So for what you're talking about here, it doesn't matter if a framework uses typing internally or not.

In any case, you can just put the different versions of transfer in the web root of each project and it works with no mappings. Guaranteed! I've got an application on HostMySite working fine using coldspring, MG and transfer with no mappings at all. If another client of theirs comes along and gets support to add a mapping to "transfer" on that server, well, my app will be broken until i can get support to get the other client to just put his version of transfer in his webroot.

I'm still hoping we'll have application specific mappings in CFMX one day soon, which might help to cover all the bases (like maybe you want to use transfer 1.0 on all the apps on your server except 2 of them, so you set up a mapping for the whole server so you don't replicate the code and can drop bug fixes in one place, and for the 2 apps that still use transfer 0.8, you use an application mapping ...).

ciao,
Nando

Ryan Guill wrote:
Hey guys,

I'm working on designing a new project, and in thinking through some
of it I came across this.  Sorry if this is a newbie question, but
just thought I would get some reactions.

When typing objects in cf, the typing depends on how the objects were
created, not on the actual path to the objects (physical path).

For instance, say I create an object called foo in the {application
root}/com/ directory, so {root}/com/foo.cfc

and I give it an init call like so:

<cffunction name="init" access="public" returntype="com.foo">

<cfreturn This />
</cffunction>

Okay, so now I go to a new page somewhere and I create an obect out of
the component like so:

<cfset variables.foo = createObject("component","com.foo").init() />

All good right?  The return type says com.foo, the create object uses
com.foo and everything works fine.

Okay, now lets say I make a new mapping in cf to the com directory,
called com_mapping.

So now I try to create an object out of the cfc using the following code:

<cfset variables.fooWithMapping =
createObject("component","com_mapping.foo").init() />

An error is thrown, because the path to the cfc that you are using the
create the object is not exactly the same as the type specified in the
returntype of the init...  Since foo is still accessible using
com.foo, and that is the actual path to the cfc, shouldn't it still
work?

If you change it to returntype="any" both calls work, but you loose
that type checking.

Now,  I know all about duck typing and the possible performance
concerns of typing, but at the end of the day, the typing was intended
to be used like this, and this seems a little illogical?  I don't have
a java background and don't know if this issue would translate well to
the java world, but I would be interested in seeing if there was some
sort of correlation.

For an example of why this matters, imagine that you had multiple
releases of the same application, myApp v1 and myApp v2 that you
wanted to have both available at the same time on the same server.  So
for example:

{domain}/myApp/v1/ and {domain}/myhApp/v2/

The same code base except v2 is just a newer copy with some new
features right?  Well lets say the application uses an external
resources such as some sort of framework.  Lets say for example its
transfer.  So v1 of the application uses v0.5 of transfer, and v2 of
the application uses v0.6 of transfer.  If transfer uses typing in its
objects (I really have no idea, ive never used transfer, this is just
an example) then you can't just use a new mapping to get to the new
version in v2 from v1.

Sorry for the long email, just curious if anyone has ran into this and
possible workarounds... because if the framework uses typing in its
objects (this would also apply to inheritance of objects I would
think) then its not really an option to go through and change return
types to "any" everywhere...



--


Aria Media Sagl
CP 234
6934 Bioggio
Switzerland
www.aria-media.com



You are subscribed to cfcdev. To unsubscribe, please follow the instructions at http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at www.mail-archive.com/cfcdev@cfczone.org

Reply via email to