I today learned that dynamically typed programming languages do type checking at run-time as opposed to statically typed languages which do so at Compile-time.(Correct me if I am wrong). What I want to know is how does at run time dynamically typed languages find out the type and how does it work? And also dynamically typed languages are called value typed language, what does it mean to say that in the case of dynamically typed languages, type is associated with value?
As I am a beginner my question would come to some of you as not a good question, please try to think from my perspective, I have just started and I am not finding this answer anywhere.
Update
From Wikipedia Page On Type System
Implementations of dynamically type-checked languages generally associate each runtime object with a "type tag" (i.e. a reference to a type) containing its type information. This runtime type information (RTTI) can also be used to implement dynamic dispatch, late binding, downcasting, reflection, and similar features.
Now What is type tag and how does it work, I mean if you could show me how in memory it is represented?
Variables in dynamic languages are usually references to classes instances, or objects (and some times built in datatypes as
int
for some languages).They can receive references to different objects (or classes instances) during their "life time" (where garbage collection exist), and their type is therefore derived by the type of the object (is it
int
,string
or an user definedPerson
?).When coming to determine the type of the object, different languages would implement this in different ways.
Python, for example, uses metaclasses to determine the type of the class, and uses that information when it comes to determine what type of object it is.
Javascript uses objects who contain in addition to their normal attributes specifiers (similarly to metaclasses), alongside the normal datatypes (
integer
,float
,character
...).