Friday, August 28, 2009

Do not put required arguments in init() if…

… if CFC persistent=”true” (in CF9 beta).

For instance, when you use ORMExecuteQuery() to return an array of that entity with init(required arg), it will throw an exception.

Wednesday, August 26, 2009

Should we abandon Instance scope in CF9?

INSTANCE scope is never an official scope, but it has been adapted by many CFer's (including myself) for writing CFC.

<cfset variables.instance = structNew()>

Common usages include:

  • dump() private variables for debugging
  • getMemento() / setMemento(struct)
  • clone()

However, CF9 brings lots of much needed <cfproperty> functionality:

  • <cfdump> will now dump all properties
  • implicit getters and setters (can be turn off optionally)
  • validation on setter (optional)
  • metadata for the almighty ORM with Hibernate

Unfortunately, all the properties are stored in VARIABLES scope by default, and it can’t be changed.  However, since <cfproperty> has become so important and powerful in CF9, should we abandon the INSTANCE scope convention? 

What do you think?

Monday, August 24, 2009

CF9 beta: cfinterface does not respect implicit getters/setters

I'm excited these days because I get to play with CF9 for a new project. However, I'm disappointed that <cfinterface> does not respect implicit getters and setters.

I was working on a CreditCard.cfc that implements ICreditCard.cfc in CF8.

CreditCard.cfc has holdername, number, expiryMM, and expiryYYYY properties defined using <cfproperty>.

ICreditCard.cfc (interface) has getHolderName(), getNumber(), getExpiryMM(), getExpiryYYYY().


I then try removing the getters from CreditCard.cfc, but CF9 complains:
"The getNumber method is not implemented by the component or it is declared as private."


Oh, that sucks. Don't you agree?

UPDATE: CF9 FINAL will generate the getter and setter methods for you when you specify accessors=true, and they Will respace the interface if the method signatures are the same!