Coding conventions for writing CFC in CF9?

With new ways to write CFC in CF9, what are some of the new coding rules for CF9?

Here are some of them that I can think of ...

+6
coldfusion coldfusion-9 cfc
source share
3 answers

Do we still need to set the attribute output = false for the component and functions in the style of the CFC script?

I wouldn’t think so. <cfscript> by its nature suppresses any spaces and needs writeOutput() to have any output whatsoever.

+2
source share

Your init () method should not return the scope of this if you call it using the syntax new my.cfc (). True story.

If you are inside cfc and want to set the property, do not use this.setFoo (), just go to setFoo (). The same goes for getFoo (). This .xxx () is like exiting the front door just to return. In addition, your access = private user getters and setters will not work, as functions will not be in this area.

"var foo" vs "local.foo" - personally, I prefer var'd variables, as there are fewer), and for 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. The 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; } 
0
source share

all functions that modify data must return some value, even if it is a boolean, which is always true at present. Functions have a way to ultimately return false

-one
source share

All Articles