02.03.2014 Views

Tornado

Tornado

Tornado

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

B<br />

Tcl<br />

■<br />

■<br />

expr and Control Flow Commands: Do not use expr in commands such as if,<br />

for or while except to convert a variable from one format to another:<br />

CORRECT: if {$id != 0} {<br />

CORRECT: if {[expr $id] != 0} {<br />

INCORRECT: if {[expr $id != 0]} {<br />

expr and incr: Do not use expr to increment or decrement the value of a<br />

variable. Use incr instead.<br />

B<br />

CORRECT:<br />

incr index<br />

CORRECT: incr index -4<br />

INCORRECT: set index [expr $index + 1]<br />

■<br />

wtxPath and wtxHostType: Use these routines when developing tools for<br />

<strong>Tornado</strong>. With no arguments, wtxPath returns the value of the environment<br />

variable WIND_BASE with a “/” appended. With an argument list, the result of<br />

wtxPath is an absolute path rooted in WIND_BASE with each argument as a<br />

directory segment. Use this command in <strong>Tornado</strong> tools to read resource files.<br />

The wtxHostType call returns the host-type string for the current process (the<br />

environment variable WIND_HOST_TYPE. if properly set, has the same value).<br />

For example:<br />

source [wtxPath host resource tcl]wtxcore.tcl<br />

set backenddir [wtxPath host [wtxHostType] lib backend]*<br />

■<br />

catch Command: The catch command is very useful to intercept errors raised<br />

by underlying procedures so that a script does not abort prematurely.<br />

However, use the catch command with caution. It can obscure the real source<br />

of a problem, thus causing errors that are particularly hard to diagnose. In<br />

particular, do not use catch to capture the return value of a command without<br />

testing it. Note also that if the intercepted error cannot be handled, the error<br />

must be resubmitted exactly as it was received (or translated to one of the<br />

defined errors in the current procedure):<br />

CORRECT: if [catch "dataFetch $list" result] {<br />

if {$result == "known problem"} {<br />

specialCaseHandle<br />

} else {<br />

error $result<br />

}<br />

INCORRECT:<br />

catch "dataFetch $list" result<br />

335

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!