6

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...

Cœur
  • 37,241
  • 25
  • 195
  • 267
Henry
  • 32,689
  • 19
  • 120
  • 221

3 Answers3

2

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.

ale
  • 6,369
  • 7
  • 55
  • 65
  • 1
    answer: http://www.coldfusionjedi.com/index.cfm/2009/8/26/Ask-a-Jedi-Impact-of-whitespace-and-script-based-CFCs :) – Henry Aug 26 '09 at 18:02
  • @Henry, when I open that link it goes to a site that doesn't look like the coldfusionjedi.com that I remember. The dates/articles jut look... wrong. Just checked his other site and it has been discontinued: http://www.raymondcamden.com/ – Scott Jibben Oct 06 '14 at 18:57
  • @ScottJibben Link updated: http://www.raymondcamden.com/2009/8/26/Ask-a-Jedi-Impact-of-whitespace-and-script-based-CFCs – Henry Oct 06 '14 at 19:49
0

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;
}
Mike Causer
  • 8,196
  • 2
  • 43
  • 63
-1

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

James A Mohler
  • 11,060
  • 15
  • 46
  • 72