In dynamic scoping, if a programmer declares a variable within the scope of a function, it is available to subroutines called from within that function. Originally, this was intended as an optimization; lexical scoping was still uncommon and of uncertain performance. In computer scientist Olin Shivers's recollection, "I asked RMS when he was implementing emacs lisp why it was dynamically scoped and his exact reply was that lexical scope was too inefficient." Dynamic scoping was also meant to provide greater flexibility for user customizations. However, dynamic scoping has several disadvantages. Firstly, it can easily lead to bugs in large programs, due to unintended interactions between variables in different functions. Secondly, accessing variables under dynamic scoping is generally slower than under lexical scoping.
in DYnAmiC scoPINg, if a pRogrammer declaRes a Variable wiTHIn the scopE Of A FuNcTIoN, it IS available to sUBRoUTines cAlLEd From Within thAT fUncTion. orIginALly, this Was intended as An opTimiZAtIon; lexicAL sCoPinG was stiLL uncomMOn And of uNceRtAin pERforManCe. iN CoMputer scientIst oliN shIverS'S REcolleCtion, "i Asked rms wheN hE WAs iMpLementIng emACs lisp why it WaS dynamiCALLY Scoped aNd HIS exacT repLy wAs tHaT leXiCal scoPe waS tOo InefficieNt." DYNAmic scopIng was also meant to prOVidE greaTer fLeXiBIlitY foR user custoMizatIons. hOwever, dynaMic scopinG has severaL DiSadVAntagEs. firstlY, it can easIly leAd tO BUGS iN laRgE PrograMs, duE tO Unintended INTEractionS beTween VariAbles iN difFerenT fuNctIoNs. sEcOndlY, accessING VariabLes undEr DynAmIC sCopINg Is geNeraLly SLoWER than UnDer lexical scOPINg.