types - Why must dynamically typed languages store variable names as strings? -


i've read dynamically typed language slower because store variable names string, can't use else? i'm asking question follow of question:

why dynamically typed languages slow?

aren't there other methods access variable using name hash lookup ? wouldn't opportunity use template programming technique ?

there several reasons, next couple. suppose, there code receives variable x , accesses field foo on it, , 1 time variable attached object of type bar, other time attached object of type baz, both have other fields , there no relationship between two. access x.foo valid in both cases, because classes unrelated, it's difficult map identifier foo integer can later used access desired field: location , type may unpredictable. add reality, imagine other classes may come , go in system, , may have field foo.

another scenario has nothing object-oriented approaches , learned @ time when lisp , similar languages invented. allow compute not statically written in code, evaluate terms @ run-time. terms may retrieved, e.g. plain strings, external files, databases, network, etc. , interpreted special function, called eval. of course, dynamically computed terms may refer existing variables. , there no other way except names.

however seems reasonable variable accesses optimized @ run-time. key issue can done in specific circumstances, not of time in statically-typed languages.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -