You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Initially, when describing the scope of accessible variables, this lesson first explains script-wide variables. Afterwards, it explains about variables defined within variables, and how only they can only be accessed within that function. My immediate thought after that was "why limit the capabilities of accessing variables?"
In other words, I think some people might question why one would put accessibility constraints on themselves for variables. Maybe someone might shrug off the idea of constraining variable scoping and define all their variables script-wide to be more free, when in reality it could lead to spaghetti code. I think a short explanation of why constraining scope could be useful.
Off the top of my head, I can think of a few reasons why you would want to limit the scope of variables to functions:
security (e.g. an animal should never be able to access a variable a separate animal)
organization (e.g. an animal should only contain and be able to access its own variables)
shadowing (e.g. defined foo in script-wide, but defined fooagain in a function)
should be avoided to avoid confusion
I'm only on Lesson 12, so maybe it is elaborated later on.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Initially, when describing the scope of accessible variables, this lesson first explains script-wide variables. Afterwards, it explains about variables defined within variables, and how only they can only be accessed within that function. My immediate thought after that was "why limit the capabilities of accessing variables?"
In other words, I think some people might question why one would put accessibility constraints on themselves for variables. Maybe someone might shrug off the idea of constraining variable scoping and define all their variables script-wide to be more free, when in reality it could lead to spaghetti code. I think a short explanation of why constraining scope could be useful.
Off the top of my head, I can think of a few reasons why you would want to limit the scope of variables to functions:
foo
in script-wide, but definedfoo
again in a function)I'm only on Lesson 12, so maybe it is elaborated later on.
Beta Was this translation helpful? Give feedback.
All reactions