I've been working heavily with Block[] for months in my research so I've read the documentation for the seemingly similar commands With[], Block[], and Module[].
Personally, I've had by far the greatest success with Block, despite With having the connotation of what I think I am trying to accomplish. Sometimes With will solve a problem where Block works as well, but often not. I haven't tried Module as much, but the documentation seems so similar.
I am sure there are very critical subtleties which make these three commands have their respective places in the world and I fear choosing the wrong one may cause problems.
My incentive for using these types of commands typically is, I work with expressions of several variables (large matrices with 7 variable dependencies), and often I wish to (temporarily) examine a lower-dimensional subspace of my expression; i.e. I may wish to "substitute" numerical values for 5 or 6 of the variables to produce a simpler expression which depends only on 2 or 1 variables. Of course, it is important for me to retain the true expression (with 7 variables) so I don't simply want to set values for the variables (I could do this and then use Clear, but this gets messy very quickly). Also, I have found that using rule substitutions like
(expr)/.x->1.45 often cause mathematica to treat x as 1.45 elsewhere. I need local variable assignments, so it seems Block, With, or Module is the way to go. But how should I chose?
(* ========================== EDIT ========================== *) When Module, for example, is wrapped inside another module, the text becomes red. Does this indicate a problem or is it normal/functioning properly?
Module[{x = 4}, (x^2 + y^2) Module[{x = 1}, (x + y)]] Block[{x = 4}, (x^2 + y^2) Block[{x = 1}, (x + y)]] With[{x = 4}, (x^2 + y^2) With[{x = 1}, (x + y)]] all of the above seem to return the desired output of
(y+1)(y^2+16) but mathematica gives slightly different variable colorings. Maybe the red isn't bad?