CreateObject("component","x.y.z")

14 views
Skip to first unread message

Alan Williamson

unread,
Mar 21, 2010, 7:52:30 AM3/21/10
to CFML Conventional Wisdom
Creating a CFC has always been a bit verbose for my liking.

CreateObject("component","x.y.z")

Considering that the vast majority of CFML developers will always be
doing a component, i am thinking that we should just default the
"component" bit.

So i am proposing this small addition:

CreateObject("x.y.z")

Thoughts?

--
aw2.0
http://www.aw20.co.uk/

Andy Wu

unread,
Mar 21, 2010, 8:03:23 AM3/21/10
to cfml-convent...@googlegroups.com
I see where you're coming from but wouldn't that introduce an
inconsistency into the language. I mean, it's always the case that the
first parameters for any function are required, with the remaining ones
optional. I can't think of any that don't obey that rule at least.

Andy

--
aw2.0
http://www.aw20.co.uk/

Matthew Woodward

unread,
Mar 21, 2010, 9:20:56 AM3/21/10
to cfml-convent...@googlegroups.com
On Sun, Mar 21, 2010 at 4:52 AM, Alan Williamson <al...@aw20.co.uk> wrote:
So i am proposing this small addition:

   CreateObject("x.y.z")

Interesting--at first blush I agreed with Andy about the inconsistency but on the other hand, the first argument is still required, but what the first argument is would change.

I kind of like it. If there's only one argument passed to CreateObject assume it's a CFC location, and if there are two arguments then treat it as usual. Saves from having to type "component" every time but doesn't break any compatibility with pre-existing code, or if people just like typing "component".
--
Matthew Woodward
ma...@mattwoodward.com
http://blog.mattwoodward.com
identi.ca/Twitter: @mpwoodward

Please do not send me proprietary file formats such as Word, PowerPoint, etc. as attachments.
http://www.gnu.org/philosophy/no-word-attachments.html

Vince Bonfanti

unread,
Mar 21, 2010, 12:44:49 PM3/21/10
to cfml-convent...@googlegroups.com
Why not introduce a new function:

    CreateComponent( "x.y.x" )

Vince


--
CFML Conventional Wisdom
http://groups.google.com/group/cfml-conventional-wisdom?hl=en?hl=en
 
To unsubscribe from this group, send email to cfml-conventional-wisdom+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Peter J. Farrell

unread,
Mar 21, 2010, 2:23:13 PM3/21/10
to cfml-convent...@googlegroups.com
I know it's Java-ish, but why not just use a keyword:

<cfset myObj = new com.maepub.project.User.init(someParam) />

The above isn't my favorite.  I'd prefer using a convention since "init" has become a convention by adding in at the end a ().  This would call a method named "init":

<cfset myObj = new com.maepub.project.User(someParam) />

Or a no argument init would look like this:

<cfset myObj = new com.maepub.project.User() />

Doing this without the () means the "init" method is *not* called (to retain backwards compat with how CreateObject works) since we don't have "real" constructors in CFML:

<cfset myObj = new com.maepub.project.User />

Or just if you not into the brevity thing or keyword idea:

<cfset myObj = new("com.maepub.probject.User").init(someParam) />

My two cents,
.Peter

Vince Bonfanti said the following on 21/03/10 11:44:

Sean Corfield

unread,
Mar 21, 2010, 2:39:46 PM3/21/10
to cfml-convent...@googlegroups.com
On Sun, Mar 21, 2010 at 11:23 AM, Peter J. Farrell <pe...@mach-ii.com> wrote:
> I know it's Java-ish, but why not just use a keyword:
>
> <cfset myObj = new com.maepub.project.User.init(someParam) />

Given that this is (almost) how CF9 does things, I can't see any
reason to change createObject() rather than just add the 'new'
operator.

> <cfset myObj = new com.maepub.project.User(someParam) />
>
> Or a no argument init would look like this:
>
> <cfset myObj = new com.maepub.project.User() />

This is exactly how CF9 does it (and how Railo will soon).

You can also do:

import com.maepub.project.User;
myObj = new User();

or

import com.maepub.project.*;
myObj = new User();

(This was also what the CFML Advisory Committee agreed on)
--
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

Matthew Woodward

unread,
Mar 21, 2010, 2:44:15 PM3/21/10
to cfml-convent...@googlegroups.com
On Sun, Mar 21, 2010 at 11:39 AM, Sean Corfield <seanco...@gmail.com> wrote:
import com.maepub.project.*;
myObj = new User();

(This was also what the CFML Advisory Committee agreed on)


I'm a big fan of this, Java-esque as it is. Makes it all the more curious that this is what they went with in CF 9 since there's so much "if you want Java, use Java" sentiment elsewhere in the syntax discussions.

Alan Williamson

unread,
Mar 21, 2010, 2:44:18 PM3/21/10
to cfml-convent...@googlegroups.com

>> <cfset myObj = new com.maepub.project.User(someParam) />

does this imply that the User object has an "init" function somewhere?

do then assume that "init" is the default/unofficial/official object
constructor?

That won't be a major problem to support in OpenBD (says he, looking at
Andy hoping not to see daggers!)

Alan Williamson

unread,
Mar 21, 2010, 2:49:19 PM3/21/10
to cfml-convent...@googlegroups.com

Matthew Woodward wrote:
> I'm a big fan of this, Java-esque as it is. Makes it all the more
> curious that this is what they went with in CF 9 since there's so much
> "if you want Java, use Java" sentiment elsewhere in the syntax discussions.

I honestly don't think there is anyone that is actually designing
this within Adobe. If there was, then half of the implementations
would never have made it past any sane discussions.

So many inconsistencies, i don't get surprised anymore.

+1 to the "new XYZ()" operator.

Peter J. Farrell

unread,
Mar 21, 2010, 2:57:09 PM3/21/10
to cfml-convent...@googlegroups.com
Alan Williamson said the following on 21/03/10 13:44:

>
>>> <cfset myObj = new com.maepub.project.User(someParam) />
>
> does this imply that the User object has an "init" function somewhere?
Yes, I believe it does.

> do then assume that "init" is the default/unofficial/official object
> constructor?
Yes, I believe it is. Somebody please correct me if I'm wrong.

> That won't be a major problem to support in OpenBD (says he, looking
> at Andy hoping not to see daggers!)
I'm going out on a limb -- I doubt Andy will oppose (I'm prepared to eat
pizza if I'm wrong).

Peter J. Farrell

unread,
Mar 21, 2010, 3:07:15 PM3/21/10
to cfml-convent...@googlegroups.com
Matthew Woodward said the following on 21/03/10 13:44:
On Sun, Mar 21, 2010 at 11:39 AM, Sean Corfield <seanco...@gmail.com> wrote:
import com.maepub.project.*;
myObj = new User();

(This was also what the CFML Advisory Committee agreed on)


I'm a big fan of this, Java-esque as it is. Makes it all the more curious that this is what they went with in CF 9 since there's so much "if you want Java, use Java" sentiment elsewhere in the syntax discussions.
Honestly, I don't care if it is Java-esque or Ruby-esque as long as it makes sense.  Honestly, Ruby is even more basic because it does away with the "new" keyword but you always have to call the constructor (called "new" in Ruby)*:

u = User.new("Peter")

HTH,
.pjf

P.s.  My depth of knowledge / use of Ruby is rather limited so keep that in mind.

Marko Simic

unread,
Mar 21, 2010, 7:19:10 PM3/21/10
to CFML Conventional Wisdom
As Sean already said, "new" operator is already implemented in ACF9
and it invokes constructor (init) by default.
So, I would not change anything about createObject function. What I
would do is to forget it as soon as possible :)
What I miss is static method call. New "new" operator creates an
instance, so, again, I need to createObject w/o expiclit call of
init() method (that is "to create reference"), and then call "static"
method.
Why we shouldn't just call static methods referencing it by its
namespace:

com.my.namespace.classname.method();

instead

c = createObject("component","com.my.namespace.classname");
c.method();

The way it is done now it total waste of time and space.

Best Regards,
Marko Simic

Sean Corfield

unread,
Mar 21, 2010, 8:13:02 PM3/21/10
to cfml-convent...@googlegroups.com
On Sun, Mar 21, 2010 at 11:44 AM, Alan Williamson <al...@aw20.co.uk> wrote:
>>> <cfset myObj = new com.maepub.project.User(someParam) />
> does this imply that the User object has an "init" function somewhere?

It will call init() it if is defined. CF9 added at least one other way
to specify a method as a constructor, I believe, but adopted the
widely used convention that init() 'is' the constructor.

Bear in mind also that when you interact with a Java object, you must
call init() in order to invoke the constructor:

s = createObject( 'java', 'java.lang.String' ).init( 'hello' );
// equivalent of new String( 'hello' )

Andy Wu

unread,
Mar 22, 2010, 7:47:21 AM3/22/10
to cfml-convent...@googlegroups.com
Peter J. Farrell wrote:
>> That won't be a major problem to support in OpenBD (says he, looking
>> at Andy hoping not to see daggers!)
> I'm going out on a limb -- I doubt Andy will oppose (I'm prepared to
> eat pizza if I'm wrong).
I wouldn't bother even thinking about what topping you're going to have.

Aiming to have it supported in OpenBD this week.

Andy

Matthew Woodward

unread,
Mar 22, 2010, 10:02:55 AM3/22/10
to cfml-convent...@googlegroups.com
On Mon, Mar 22, 2010 at 4:47 AM, Andy Wu <an...@aw20.co.uk> wrote:

Aiming to have it supported in OpenBD this week.

Awesome--can't wait.

Peter J. Farrell

unread,
Mar 22, 2010, 11:07:19 AM3/22/10
to cfml-convent...@googlegroups.com
Andy Wu said the following on 22/03/10 06:47:
Darn it. I was aiming for an excuse to get a mock duck, yellow banana
peppers, rinotta and bbq sauce. Anyways, I'm excited for this new
keyword / operator.

.pjf

Reply all
Reply to author
Forward
0 new messages