ࡱ > 0 2 / M bjbj== "( W W l "
"
"
"
.
, f
f
f
f
f
f
f
f
? A A A A A A $ v e f
f
f
f
f
e f
f
z f
^ f
f
? f
? x ? f
Z
IEW 6 "
? 0 , d L ? Developer Neat Tricks
By Ray Camden
1) Read the Docs!
I strongly urge developers to read the documentation shipped with ColdFusion. Dont skim. Read. You will be surprised by how much you forgot. (Examples: Max(), YesNoFormat())
2) Remember the Brackets!
Far too often I see people using Evaluate for Structs. Do not forget that you can grab an arbitrary value out of a structure using bracket notation instead of evaluate. Never use evaluate where you dont have to. Not only is it slow, but the code is harder to read.
Use:
key = name;
val = struct[key];
Instead of:
key = name;
val = evaluate(struct.#key#);
Queries can use bracket notation as well. If you are looping through a query where you dont know the column names, instead of using evaluate, simple pass the column name (grabbed from QueryName.ColumnList) as a struct key: Query[col][row].
3) Remember the (Default) Structs!
Following up on tip 2, dont forget that things like the Form and URL scopes are also structures. If you need to loop through form fields sent, simply treat it as a structure. Example:
Form.#Field# = #Form[Field]#
4) Save yourself from Locks
Store shared memory variables in the request scope for easy access.
5) CFSAVECONTENT
1) Use it to save the results of CFEXECUTE. CFEXECUTE only has two options, save to a text file or save on screen. By using CFSAVECONTENT, you can get the results into a variable.
2) Use it for quick and dirty caching (ala cfa_generatedcontentcache). See http://www.allaire.com/handlers/index.cfm?ID=21422. (And for those of you who use Spectra, you cant miss cfa_generatedcontentache.)
6) Use custom buttons in CFStudio
I have two buttons defined in Studio that I use 10-50 times a day. One simply outputs , and one simply outputs . Studio/HomeSite have very nice customization options. Look into them!
7) Use CFMODULE to avoid custom tag conflicts
Deploying to a shared server? If you use a large number of custom tags, you may want to consider using . Using CFMODULE means you never have to worry about custom tag name conflicts (and allows you to use your own folder for tags). CFMODULE allows for anything you can do in CF_ style. (Including end tags.)
8) CFDUMP
The absolute best tag every created. Learn to love it. This tag will display any value and is the debuggers best friend.
9) CFFLUSH
Have a page thats a bit slow? If you dont have the time to figure out why its slow, slap a CFFLUSH on the page. Takes two seconds and it will increase the apparent speed of the page with little no effort. (That being said after using CFFLUSH, do not forget to come back at a later time and try to find the bottleneck.)
10) And speaking of bottlenecks
Need to find out what part of a page is slowing you down? Use GetTickCount() to measure the speed of portions of your page. Example:
Code block 1 took #Time1#ms
Code block 2 took #Time2#ms
Spectra users may not know that a custom tag exists, cfexecutiontime, that will do all the above for you in a much simpler fashion.
11) Line breaks can be used in variables
If you need a text string with line breaks in it, you can simply enter them while creating the string. It doesnt look pretty, but works just fine. This is useful when creating variables for text between PRE tags, or for CFMAIL.
WriteOutput("
This is the foo that went to blah.
I love my cable internet service provider.
Really.
");
str = "Another
funky
string
";
Writeoutput(str);
#str2#
12) Forgot the Docs? GetFunctionList()
Did you know you could get a list of all the functions? The function, GetFunctionList(), returns a structure where each key represents one of the ColdFusion functions.
% 9 9 H v j I
K f j _ b >
8 ) P 6OJ QJ ^J >*B*OJ QJ ^J ph CJ OJ QJ ^J aJ 5OJ QJ ^J OJ QJ ^J 5CJ OJ QJ ^J aJ 2 $ % 8 9 % 9 : F G V v w i j G H s ` s X
- . I a 2 > ? & J T i j
7 8 ) 8 \ ( ) P Q 1h/ =!"#$%
i 8 @ 8 N o r m a l CJ _HaJ mH sH tH <