People on this board have talked about programming as a gear in your brain that, to a first approximation, you have or you don't. I'm wondering if there's some well put-together resource you can direct someone with zero experience and just a web-browser to and say "if you're having fun an hour from now, you have the gear, good luck" -- maybe something on Khan academy?
(I learned to program a long time ago, and I started with BASIC program listings in my math textbook -- I don't actually know what the optimal onramps are now.)
My post didn't indicate this, but the most common source of scope is functions; calling a function starts a new scope that ends when the function returns. Especially in this case, it does often make sense to use the same variable name:
Will have prior=prior, evidence=evidence, and is a good naming scheme. But in most languages, modifying 'evidence' in the function won't affect the value of 'evidence' outside the scope of the function. This sometimes becomes confusing to students when the function above gets called like so:
Because their previous model relied on the names being the same, rather than the coincidence of naming being merely helpful.
Overall, I would say that this is still a fertile source of errors, but in some situations the alternative is to have less readable code, which is also a fertile source of errors and makes fixing them more difficult.
Your confusion is due to using "scope", which is actually a lexical concept. What you're dealing with here is variable substitution: in order to evaluate a function call such as
posterior = ApplyBayes(prior, evidence1)
, the actual function arguments need to be plugged into the definition ofApplyBayes(·, ·)
. This is always true, regardless of what variable names are used in the code forApplyBayes
.