This question is interesting mainly for beginners, but the answer i wrote to my own question could be also interesting for advanced users.
Introduction: While writing huge blocks of code, especially inside of a Module it can be very hard to debug your code. You quickly end up insering Print everywhere you want to check the value of a variable like:
MyModule[arg_] := Module[{a, b, c},
a = Simplify[arg];
Print[a];
b = Integrate[a, {x, -\[Infinity], \[Infinity]}];
Print[b];
(** much more code **)
Print[c];
]
The problem here is, that you only get the values of the variables and if you have a lot of variables you can not tell easily wich output belongs to wich variable. Counting the outputs is not an option for big modules. To match the values to the variablenames You could explicitly write the name of the variables inside the Plot, like this:
MyModule[arg_] := Module[{a, b, c},
a = Simplify[arg];
Print["a = ",a];
b = Integrate[a, {x, -\[Infinity], \[Infinity]}];
Print["b = ",b];
(** much more code **)
Print["c = ",c];
]
This strategy is ok, for small blocks of code, but its getting annoying very fast if you have to insert Print["variable = ", variable] everytime you want to check a variable. If you test your module maybe inside another module all the PrintOutputs will fill your notebook. So if you dont want to see the debug-outputs anymore, you would have to commend every Print, to deactivate it.
So my questions are: How can i do this more elegant more automatically? How can one switch the outputs of Print on/off? How can i get information of the variablename and its value without writing the variablename manually inside of Print?
Have a look at my answer if you want to know my solution:
Module
! $\endgroup$Assert
? $\endgroup$