G'day:
I was typing this response on Stack Overflow, and just as I was finishing, the question was closed and I was unable to save it. What a bunch of pricks the rule-makers on StackOverflow are.
I'm not having my work wasted, so I'm publishing it here instead.
Obviously any thoughts or elaborations are welcomed.
The question has been cross-referenced to this one: "Differences between New/CreateObject() vs EntityNew() in CF9 for persistent CFC?". It answers the same question, but very nebulously (kinda appropriately for the general tenor of the question).
--
Adam
I was typing this response on Stack Overflow, and just as I was finishing, the question was closed and I was unable to save it. What a bunch of pricks the rule-makers on StackOverflow are.
I'm not having my work wasted, so I'm publishing it here instead.
Obviously any thoughts or elaborations are welcomed.
Question:
In ColdFusion which way is better to create a component object CreateObject() or EntityNew() or New keyword
I was writing some code in ColdFusion using CFC components, when I got bit confused on using different ways to create a object of a component. I would appreciate if someone please let me know which method of creating a object is better. CreateObject(), EntityNew() & New keyword. I read through few blogs and got mixed answers, some said Entity New is faster as compared to Create Object. I also found that the syntactical different is better in EntityNew(). I would appreciate if I can get some thoughts on from anyone. Thanks.
My answer:
This is a very nebulous question, and I am going to vote to close it once I post this.That's it.
Unless someone can come up with real-world performance penalties usingnew
,createObject()
,<cfobject>
or<cfinvoke>
, I'd not bother listening to them. There will not be a meaningful difference. They are dwelling in the realms of micro (and premature ~) optimisation.
All those options I list above are slightly different toentityNew()
, which is specifically intended for creating ORM-based objects. The others are more generic. But, again, performance-wise there will be no real-world consideration here.
I do not use tags when I can avoid it. So that discounts<cfobject>
and<cfinvoke>
for consideration IMO.
All of this is opinion though.
As I said,entityNew()
is specifically designed for creating ORM objects, so there might be something to be said to using that in a mixed environment that has a mix of ORM-based and vanilla objects.
As forcreateObject()
andnew
? I now reservecreateObject()
for Java objects, and usenew
for CFML objects. For code clarity.
Oops... someone else has closed this question. I guess this might be a waste of time!
The question has been cross-referenced to this one: "Differences between New/CreateObject() vs EntityNew() in CF9 for persistent CFC?". It answers the same question, but very nebulously (kinda appropriately for the general tenor of the question).
--
Adam