Josh wrote:On the other hand, it should be up to everyone to write their code the way they want.
The world is not that simple. A programming language is not just for people to communicate with a computer, but it's also for people to communicate with each other. That's why e.g. we are sharing code here on the forum. An effect of that proposed strange programming style is confusing less experienced users, as we've seen here already.
Josh wrote:Additionally, Macros or IncludeFiles could cause situations where a variable is declared repeatedly.
Perhaps with
Define or
Global. But with
Protected
I can't recall ever having read that someone had a problem with this during 12+ years here on the forum.
Josh wrote:there is definitely no reason why a repetition of Protected should not be allowed
A programming language shouldn't encourage people to use poor programming style.
The main problem with spreading variable declarations all over a procedure probably is, that
this defeats the purpose of EnableExplicit!
EnableExplicit is very useful for detecting typos.
So if e.g at the beginning of a procedure it reads
and later in the procedure it reads
then
the compiler will complain about this typo.
But if we write
somewhere in the middle of a procedure, then
this typo will not be detected even if
EnableExplicit is used!
In contrast, declaring all protected variables in one place dramatically reduces that risk. When it reads
at the beginning of a procedure, we will immediately see that this looks suspicious, and we will check whether or not this is actually intended.