Ask a Jedi: Impact of whitespace and script based CFCs
Henry asks:
Does CF9 script style CFC still needs to set attribute output=false for component and function?
In my - admittedly - very limited testing, the answer appears to be no. I created a component with a large amount of white space in both the function and around it as well:
2
3
4public string function sayHello() {
5
6
7
8
9
10
11
12
13
14
15
16 return "Hello World!";
17
18}
19
20
21}
I duplicated this component but added output="false" to both the component and method:
2
3
4public string function sayHello() output="false" {
5
6
7
8
9
10
11
12
13
14
15
16 return "Hello World!";
17
18}
19
20
21}
To test then I created an instance of both and wrapped the sayHello call:
2<cfset goodWS = new testws2()>
3
4<cfoutput>
5Testing bad: -#badWS.sayHello()#-<br/>
6Testing good: -#goodWS.sayHello()#-<br/>
7</cfoutput>
The result was the exact same. No additional white space from the creation of the CFC or the call either. I even tested making an instance of the first CFC with createObject, just to see if it made a difference, and it did not. Of course, it isn't like the output="false" argument is ignored. If you write a CFC method that outputs directly to the screen, then it does matter. Consider:
That function will work just fine, but if you modify it a bit...
Now you have a useless function. The output="false" will suppress the writeOutput>

Interesting.
In CFAdmin what is your 'Enable Whitespace Management' set to? By default in CF9 its now checked and I wonder if that changes things.
Re: Script and Tags
We've got the best of both worlds now :)
@Jared: Yeah, I believe you are 100% right, and it is kind of obvious now, but at the same time, good to confirm.
I tend to be anal about output="false" in my CFCs, but won't be bothering with it when i do script based ones.
I cannot get teh brainz to fully engage today. ;)
Does anyone know if it's possible to call custom tags using script-based syntax? If so, I wonder what would happen then.
Thanks!
Just on the whitespace thing. There's still a slight use case for specifying output=false on script-based functions & components.
If the script code includes a tag-based file, the whitespace from the tag-based file still outputs (if whitespace management is off, natch).
It'd be questionable form to be including files from within a function, but it's still possible, so maybe worthwhile tucking this thought away in the corner of ones brain.
--
Adam