summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2023-03-30 16:55:47 +0000
committerOmar Rizwan <omar@omar.website>2023-03-30 16:55:47 +0000
commitbce7878f2a86f71bf643d52cde61eefc9bd96cda (patch)
tree1f2f590fe2712710bdb5d603a4b6b29cb529f51a /docs
parentMerge pull request #26 from FolkComputer/ac/tryKeyboard (diff)
downloadfolk-bce7878f2a86f71bf643d52cde61eefc9bd96cda.tar.gz
folk-bce7878f2a86f71bf643d52cde61eefc9bd96cda.zip
style guide: return
Diffstat (limited to 'docs')
-rw-r--r--docs/tcl.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/tcl.md b/docs/tcl.md
index 234e5e63..0bcea651 100644
--- a/docs/tcl.md
+++ b/docs/tcl.md
@@ -58,6 +58,19 @@ subfolder) or printed programs.
Use `try` (and `on error`) in new code. Avoid using `catch`; it's
older and easier to get wrong.
+#### Return
+
+In general, don't use `return` if it's the last statement in a code
+block. Just put the statement there whose value you want to return.
+
+Bad: `proc add {a b} { return [expr {$a + $b}] }`
+Good: `proc add {a b} { expr {$a + $b} }`
+
+Bad: `set x 3; return $x`
+Good: `set x 3; set x`
+
+You should use `return` only when you actually need to return _early_.
+
#### Tcl datatypes
Create a namespace for your datatype that is an ensemble command with