Reputation: 32905
With the new ways of writing CFC in CF9, what are some of the coding convention new to CF9?
Here are some I can think of...
init()
method that returns itself, since New
will call init() if found.init()
if it is an ORM entity, otherwise expect Exceptions...THIS.setXXX
in where XXX is property name inside init(), so that it will call the implicit setters or custom setter if available.isNull(arguments.optionalArg)
instead of isDefined()
Upvotes: 6
Views: 1109
Reputation: 11120
all functions that alter data should return some value even if it is a boolean that is currently always true. Functions have a way of eventually needing to return false
Upvotes: -1
Reputation: 8314
Your init() method doesn't have to return the "this" scope if you are calling it using the "new my.cfc()" syntax. True story.
If you are inside a cfc and want to set a property, dont use this.setFoo(), just go setFoo(). Same goes for getFoo(). The this.xxx() is like going out the front door only to come back in. Also, your access=private custom getters and setters wont work as the functions wont be in the this scope.
"var foo" vs "local.foo" - personally, I prefer var'd variables as there is a) less code to type, and b) less code to read.
// there isnt a huge difference here
var today = now();
var tomorrow = dateAdd( 'd', 1, today );
local.today = now();
local.tomorrow = dateAdd( 'd', 1, local.today );
// but when you start getting more complex examples, it quickly blows out
var out = method( var1, var2, var3, var4, var5 );
local.out = method( local.var1, local.var2, local.var3, local.var4, local.var5 );
Use javadocs style comments. Documentation is your friend.
/**
* @hint This is a hint for the whole function
* @arg1 This is an argument hint
* @arg2 This is another argument hint
**/
public void function myFunction( string arg1 = 'default', boolean arg2 ) {
return true;
}
Upvotes: 0
Reputation: 6430
do we still need to set attribute output=false for component and functions in script style CFC?
I wouldn't think so. <cfscript>
by its nature suppresses any whitespace and needs writeOutput()
in order to have any output at all.
Upvotes: 2