In general, if one wants to define local variables and local constants, which of the following is the best programming practice in terms of performance and code "safety"? (Assume Block
is not appropriate.)
With
insideModule
Module
insideWith
Define constants along with variables using just
Module
Bonus Question
Is the answer the same if Block
is appropriate in place of Module
?
With
outermost andModule
as inner as possible, even if that means using nestedWith
s. (Reason: immutable beats mutable.) And avoidBlock
unless you know why you must use it. But I'll listen to whatever the CS guys have to say. $\endgroup$With
, e.g.With[{a = 2}, {b=a^2}, {c=b^2}, c]
$\endgroup$