I'm putting my new copy of Mathematica 10 through its paces and I noticed a weird change in the colouring scheme that I find very annoying, and I'd like to get some insight into why it's happening.
The change happens, as far as I can tell, for variables that have been set in some scoping construct which are then used inside of a Manipulate command. Thus, for example, the code
Module[
{A = 1},
Manipulate[
Plot[
A Sin[k x]
, {x, 0, 20}
]
, {k, 1, 10}
]
]
renders differently in the Mathematica 9 and 10 frontends:

Playing around in Edit > Preferences > Appearance > Syntax Coloring > Errors and Warnings, the error class that this is attributed to is
Variables that will go out of scope before being used
though what that means exactly isn't very clear to me. Therefore, I have some questions:
Is this in fact an incorrect usage? If so, why, and what alternative construct should I use? (I notice, in particular, that in version 10 the red colour is displayed for Block and Module but not for With.)
Why did this only start happening in version 10? Which version is right?
If this sort of code is OK, can I safely disable this sort of error marking? What risks does that entail?
ModulewithinManipulate(and I think nesting it the other way around is what caused the syntax warning because the Manipulate did not play nice with the Module outside of it). Or as you said you can useWith, and in this case it's acceptable to do so asAis basically just a constant that does not change its value when the code is run. – seismatica Jul 17 '14 at 12:04Moduleinside theManipulate) is preferable? – Emilio Pisanty Jul 17 '14 at 12:05ModulewithinManipulate, yourModulevariables can depend on the manipulate parameter, whereas you cannot achieve this the other way around (as the manipulate parameter disappears outside of the scope of the Manipulate block). You can try this to see what I'm talking about: 'Manipulate[Module[{A = k}, Plot[A Sin[3 k x], {x, 0, 20}]], {k, 1, 10}]. Of course in your case that's not going to be important since your Module variable does not change, hence the use ofWith` will be just fine. – seismatica Jul 17 '14 at 12:17Module[{A}, Manipulate[A = k; Plot[A Sin[k x], {x, 0, 20}], {k, 1, 10}]]works fine in both v9 and v10, but only v10 colours it as incorrect syntax. – Emilio Pisanty Jul 17 '14 at 12:29A(or rather the temporary variableA$xxxgenerated byModule, wherexxxis some number) will be kept alive by theManipulateeven after returning from theModule. Now the variable won't go away as long as it is referenced, which I actually consider an useful feature (it allows you to implement closures). At least that's how it is in Version 8; one would hope that it didn't change in v10. Does v10 also mark thevin the following code red?Module[{v=0},next[]:=v++]– celtschk Jul 17 '14 at 13:07Withinstead of aModule. – Emilio Pisanty Jul 17 '14 at 13:54v?Module[{v=1},Hold[v]]? What aboutModule[{v=1},v]? AndModule[{v=1},v;0]? AndModule[{v=1},Hold[v];0]? – celtschk Jul 17 '14 at 16:43vs. The problem, as you suggested originally, is with expressions of the formModule[{v}, Dynamic[v]]where the Dynamic output would break the localization of the variable. – Emilio Pisanty Jul 18 '14 at 10:35Module[{v=0},Print[Hold[v]];next[]:=v++]and then evaluate the variable outside the module; you'll see it has still the value assigned in the module. The same is true forModule[{v=1},Hold[v]](here you get the variable name right in the result, so noPrintis necessary to reveal it). Also note that while the behaviour withBlockandManipulateis pretty bad, I don't see an issue with the correspondingModulebehaviour; … – celtschk Jul 18 '14 at 10:58Module. – celtschk Jul 18 '14 at 10:59$'d variable to leak its value to the outside, but they are not coloured red. I'm unsure, then, of how (un)desirable this feature actually is. What exactly do you mean by "implement closures"? – Emilio Pisanty Jul 18 '14 at 11:04DynamicModuleI think I now figured out what the problem with Module+Manipulate probably is: Dynamic content (likeManipulate) is stored across sessions. However a normalModulevariable is not stored that way. I guess that would create problems as soon as you save the notebook and later open it in a new instance of Mathematica. – celtschk Jul 18 '14 at 11:10