Jump to content
  • Advertisement
Sign in to follow this  
brightknight

Whats the difference between static, inferred and dynamic types

This topic is 758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Distinction  between static, dynamic and inferred languages is not something universal across different languages. Specify please, where did you read about this distinction or what language / system are you talking about.

Share this post


Link to post
Share on other sites
So the thing is I heard that python has dynamic types, and c++ static types, and somewhere along the way I heard the word inferred types. So I was wondering what'sthe difference between them

Share this post


Link to post
Share on other sites

Static types are fixed. Variables are declared as specific types and their types don't change. 

// x is forever an int
int x;

Dynamic types need not be declared and the type can change. Variables can be initialized with one type and later assigned a different one.

// x is an integer type of some kind
var x = 10;

// Now it's a string type
x = 'ten'

Type inference occurs when no type is specified and the compiler determines what the type should be based on the type of the initializer. The dynamic type example I show above uses type inference for both the initialization and the assignment. C++ and D also support it.
 

// In this D code, x is inferred to be an int and y a float,
// but they are still statically typed (i.e. the types can't be changed)
auto x = 10;
const y = 20.0f;
Edited by Aldacron

Share this post


Link to post
Share on other sites

Yes, as Aldacron said, but the correct terms are 'static type system' (not 'static types'), 'dynamic type system' and 'type inference'. A language will have either static type system or dynamic type system (languages does not usually have both). Some static type systems can have type inference, all dynamic type systems usually have type inference.

 

Also - term type inference is slightly broader, it can refer to the process of retrieving some informations about a data type using vtable or something else.

Edited by Ivorne

Share this post


Link to post
Share on other sites

A language will have either static type system or dynamic type system (languages does not usually have both). Some static type systems can have type inference, all dynamic type systems usually have type inference.

 

 

C# has static and dynamic typing along with type inference, although its inference could be better sometimes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!