-
Notifications
You must be signed in to change notification settings - Fork 80
Using scopes explicitly in code
Railo has delivered very many presentations about performance and code readability. Here is what they recommend to any of their customers and programmers:
- Scope everything BUT the closest scope
- In Functions this is the local scope
- In templates it is the variables scopt
- The above two do not scope
This is a simple rule to follow and therefore it is easy to understand. In order to support this pattern in Railo, just turn off scope cascading and that will help you scope accordingly.
- If you use the variables scope in Adobe ColdFusion even in Templates, this decreases the performance of variable accesses by a factor of 4!
- This is because ACF assumes there might be a local variable called variables first and then assumes it is the variables scope
If you are NOT scoping your variables, and are worried about performance, this is a comparison between ACF and Railo and the access times for scoped vs. unscoped variables:
If you use
<cfoutput>#variables.a#</cfoutput>
in ACF it takses 459ms (in my example) if it is just
<cfoutput>#a#</cfoutput>
It takes 47ms
In general unscoped variables are slower (except for this example above which is incredibly different)
In Railo the difference is not too bad so it really doesn't matter, but as a general rule of thumb:
Scope everything, except the closest scope.
- Getting to know Railo Server
- Railo Server features & specifications
- Getting started with Railo Server
- Installation & configuration
- Railo Server Versions
- Developing with Railo Server
- Deploying Railo Server apps
- Managing Railo Server apps
- Railo Server Extensions
- Useful resources & further reading
- Developing & debugging Railo Server
- FAQs