http://coldfusion.com logo
#cfml-general
Title
# cfml-general
p

paolo79

04/28/2022, 6:03 PM
Hi, the default "output"
function
attribute in cfscript is true?
m

Myka Forrest

04/28/2022, 6:06 PM
If the default was true, then
script_output1()
should cause "script_1" to display, but it doesn't.
s

sknowlton

04/28/2022, 6:09 PM
in CFCs it's usually set on the component level, and also defaults to false IIRC
but can then be overridden on the function level
d

Dave Merrill

04/28/2022, 6:12 PM
My possibly but probably not out of date understanding is that cfscript outputs nothing unless you call writeOutput(), writeDump(), and possibly some other explicitly output related functions. Plain text without one of those doesn't output anything.
b

bdw429s

04/28/2022, 6:21 PM
@paolo79 What @Dave Merrill said is correct. Just because script functions default output to true, that doesn't mean that random strings you declare in the functions are going to be send to the page!! The following line of code is valid CFML
Copy code
"<br>script_1";
BUT IT OUTPUTS NOTHING. All it does is declare a string which is not set into any variable. Unlike tags, script requires you to explicitly output to the page buffer with
Copy code
writeOutput( "<br>script_1"; );
👍 1
d

Dave Merrill

04/28/2022, 6:29 PM
I think the somewhat bogus assumption is that cfscript is for "logic", and tags are for rendering. That's definitely how it appears from that behavior. In reality, I definitely do rendering in cfscript too, it's just way cleaner code in many cases, unless you have a big block of html with a few expressions embedded. Similar assumptions are behind many frameworks only supporting cfm files as renderers, not cfcs. I whine about this every few years and get pilloried for it, not least by the esteemed Mr @seancorfield, who no doubt will reprise that role shortly ;)
s

sknowlton

04/28/2022, 6:29 PM
my pillory isn't quite as robust as his, but you can borrow it until he gets here
d

Dave Merrill

04/28/2022, 6:30 PM
Appreciate it 🙂
s

sknowlton

04/28/2022, 6:31 PM
2005: render in tags because everything is tags 2012: move logic to script because it's script and that's what it's for 2020: talk trash about people who concatenate SQL or write views in script 2022: rendering is done in react/vue anyway, sorry CF
😆 2
1
s

seancorfield

04/28/2022, 6:35 PM
makes no comment whatsoever... uh-huh... definitely not commenting on this
p

paolo79

04/29/2022, 7:05 AM
thanks for all the replies. my doubt is related to the fact that with <cffunction> without output attribute, memory leaks are generated in the JVM for this reason I try to understand whether to specify it always the same or not, but from what I have read it seems that in cfscript this should no longer happen
b

bdw429s

04/29/2022, 1:26 PM
with <cffunction> without output attribute, memory leaks are generated in the JVM
@paolo79 I've never heard of this. Do you have a link to an article or something showing this so-called memory leak? This is new to me.
1
Now, perhaps you mean to say that unwanted text would "leak" (and I user the term loosely) out to the page if you didn't set output=false in a function. But that's not the same as a "memory leak... in the JVM".
The
output
attribute is the same, works the same, and defaults the same regardless of whether you have a tag or a script based function
The behavior that is different is really about script vs tags and what it takes in each case to contribute text to the pages's output buffer.
p

paolo79

04/29/2022, 4:04 PM
at this topic i've found the old link http://wiki.mxunit.org/display/default/How+cfcomponent+output%3Dtrue++can+affect+memory+consumption but the behavior may now be different. Since we are migrating our code from "tag" to "cfscript" I was trying to figure out whether to keep it or remove it
b

bdw429s

04/29/2022, 4:06 PM
@paolo79 "memory consumption" is not the same as a "memory leak". Also, it doesn't really matter unless you're on Lucee 5.3+ because Adobe CF and previous versions of Lucee still track all output during the method execution only to discard it at the end of the invocation. This is what allows you to dump/abort in the middle of an output=false method and still see the output.
p

paolo79

04/29/2022, 4:14 PM
thanks @bdw429s - "memory consumption" is correct term. We use ACF, so do you think it appropriate to still use output=false to avoid overload problems?
b

bdw429s

04/29/2022, 4:15 PM
you should use output=true/false based on whether or not you need output to be emitted from a function
I believe you're prematurely optimizing something that probably has no effect on your app.
Since cfscript doesn't output anything unless I explicitly tell it to, I don't tend to bother changing the
output
attribute on my script-based code.
p

paolo79

04/29/2022, 4:17 PM
but if 99% is not used, omitting it might have performance issues with ACF?
b

bdw429s

04/29/2022, 4:17 PM
99% of what
In script based code there IS NO OUTPUT unless you output it yourself
p

paolo79

04/29/2022, 4:18 PM
of all our methods in the components
b

bdw429s

04/29/2022, 4:18 PM
But again, please stop worrying about a few KB of memory here and there and use the setting as it's intended-- based on whether you need to output anything or not.
So if you have tag-based methods and you don't need to output anything from them, then set it to false. If you have script-based methods, I wouldn't really worry about it unless you're specifically trying to suppress some sort of debugging output or something in your code.
👍 1
d

Dave Merrill

04/29/2022, 4:20 PM
^^^ This. @paolo79, you're complicating your life by optimizing for this. You don't need to explcitly shut output off in a context where no output is generated in the first place.