Second beta of Railo 3 out

Just read this on the Railo 3 listserv. The second beta is out. A few new features were added, including the shorthand array/struct support CF8 has and cfdocument/cfpdf support. One really interesting update is the ability to specify where unscoped variables go in a UDF. Consider this example:

<cfscript>
function doit(y) {
   x = 2;
   return x*y;
}
</cfscript>

<cfoutput>#doit(5)#</cfoutput>
<cfdump var="#variables#">

As you can see, I have an unscoped X variable. When I dump the Variables scope, I see doit and X. However, I can now jump into the Railo Admin...

when I change the setting to "Always" as you see in the screen shot, now the x variable is automatically placed in the var scope instead.

You can grab the latest build (for all OSes) here.

Comments

Is the "y" variable also put into the var scope automatically?
# Posted By Gus | 6/27/08 7:43 AM
No - y is an argument.
# Posted By Raymond Camden | 6/27/08 7:44 AM
@Ray
DUH! <cfgroggy who='gus'/> I haven't finished my first cup of coffee yet!

y is a variable in the argument scope.
# Posted By Gus | 6/27/08 8:05 AM
I didn't realize this wasn't already in Railo? They have a lot of language configuration stuff in the admin like this which all helps performance. They have a scope cascade setting to make variable lookup faster, settings for Application.cfc to make lookup of that faster on every request and so on.

Good to know about the array / struct shorthand.
# Posted By Sean Corfield | 6/27/08 1:57 PM
Yeah, the stuff in the admin is -very- interesting. I should maybe do a blog entry on these options.
# Posted By Raymond Camden | 6/27/08 1:59 PM
What if x is setup as variable.x within the component and the developer forgets to place variable. before x when it is used within a method.

Because, correct me if i'm wrong, but if variable.x is set on the component level then x (without variables.) will refer to the variable scoped x?

Is the engine smart enough to know that x is set on the variable scope level so setting x to a var scope can be bypassed?
# Posted By Pat Santora | 6/27/08 2:02 PM
I just tested this (and btw, you should test this too, it is SUPER trivial to download, unzip, and run railo. No install is required). I added

cfset varibles.x = "orig"

on top of my script. When I ran the CFM, it correctly considered my X a local var scope variable automatically. So X worked fine in the UDF and did not overwrite my variables.x. So basically with this function on, if you do 'x' it will ALWAYS assume its variable scope.

To me - that's a good thing. If you want to use the variables scope inside a udf or method, it makes sense to properly address it (ie, variables.x)
# Posted By Raymond Camden | 6/27/08 2:41 PM
Right. That's what I thought.

So it sounds like there may need to be a cleanup strategy that developers may need to take if they happen to not have "variable." before variable scoped variables.

Good to know info. Thanks for testing this Ray and hope things are going well for you and Sean at the new place!
# Posted By Pat Santora | 6/27/08 3:45 PM
Luckily this works fine with my own personal naming rules.

CFMs: Always use full scope for everything but variables scope. So X means variables. And I use url.x for, well, url.x

CFCs: Full scope for everything possible. You can't "scope" var scope stuff, so if I see "x" by itself, it means var scope.
# Posted By Raymond Camden | 6/27/08 3:55 PM
Hey,

Cool feature, would like to see that in Adobe version.
# Posted By Dale Fraser | 6/27/08 7:08 PM
I've always been curious why ColdFusion doesn't assume that these variables are private / local unless otherwise specified. Anyone know?
# Posted By Allen | 6/27/08 10:15 PM
It is following the same rules as JavaScript. Consider this block:

<script>
function foo() {
   x = 1;
   return x*2;
}

function goo() { alert(x); }

foo();
goo();
</script>

This will alert 1 showing that x 'leaked' out. But if you var scope x, then goo will have an error because x is not defined.
# Posted By Raymond Camden | 6/27/08 11:20 PM
I'm not quite sure I follow the logic of making it match javascript, particularly when it detracts from the whole idea of RAD. The need to var scope everything just requires a lot more typing (and overlooking even one can cause real headaches and wasted time tracking down the problem). I really applaud the folks at Railo because they really seem to have a great feel for adding things to the language that really can save developers a lot of time. Since I have to code for both platforms though, I'll just have to hope these kinds of features make their way into ColdFusion eventually as well!
# Posted By Mary Jo Sminkey | 7/11/08 8:18 PM