Mathematica: TIP: Start with With, update to Module as needed.

Webel IT Australia promotes the amazing Mathematica tool and the powerful Wolfram Language and offers professional Mathematica services for computational computing and data analysis. Our Mathematica tips, issue tracking, and wishlist is offered here most constructively to help improve the tool and language and support the Mathematica user community.
DISCLAIMER: Wolfram Research does not officially endorse analysis by Webel IT Australia.
Icon class
icon_class
far fa-sticky-note
icon_class_computed
far fa-sticky-note
Note kind
Policy level
Keywords

It is a good idea to start with a With, which does not permit the renaming of initial local variables, then Migrate to a Module as needed. It's not just that With uses slightly less overhead (mostly, depends on the Expressions used), it promotes a slightly different workflow, by making it exactly clear what is an "input" (other than the function args) and what depends on those local variables.

f[y_] := With[
  { x = 1.234567 },   
  x y
];

If you need to upgrade to Module because you've changed a local variable within the scope of a With, it will warn you:

f[y_] := With[
  { x },

  x = 1.234567^y; (* ERROR: Attempt to set local With variable *)
  x + x^2 + x3
];
The exact message depends on what you have attempted to overwrite and how, typically it's something like this:

With::lvws: Variable x in local variable specification ...
Upgrade:
f[y_] := Module[
  { x },
   
  x = 1.234567^y; (* OK: inside a Module *)
  x + x^2 + x^3
];
Visit also:
Relates to
Related notes
Related notes (backlinks)
Related snippets (extracts)
Visit also
Visit also (backlinks)
External links