Inferred Type and Dynamic typing
Asked Answered
M

3

9

In programming language what is the difference between Inferred Type and Dynamic typing? I know about Dynamic typing but don't get how dynamic typing is differ from Inferred Type and how? Could someone please provide explanation with some example?

Mainsail answered 6/7, 2014 at 18:4 Comment(0)
S
16
  • Inferred type = set ONCE and at compile time. Actually the inferred part is only a time saver in that you don't have to type the Typename IF the compiler can figure it out.

    Type Inference is often used in conjunction static typing (as is the case with swift) (http://en.wikipedia.org/wiki/Type_inference)

  • Dynamic type = no fixed Type -> type can change at runtime


static & inferred example:

var i = true; //compiler can infer that i most be of type Bool
i = "asdasdad" //invalid because compiler already inferred i is an Bool!

it is equal to

var i: bool = true; //You say i is of type Bool
i = "asdasdad" //invalid because compiler already knows i is a Bool!

==> type inference saves you spell out the type if the compiler can see it

BUT if it were dynamic that would work (e.g. objC) as the type is only based on the content at RUNtime

id i = @YES; //NSNumber
i = @"lalala"; //NSString
i = @[@1] //NSArray
Shiverick answered 6/7, 2014 at 18:12 Comment(4)
Are you saying Inferred type = static typing?Mainsail
yes. it just saves you from typing the type if the compiler can figure it out anywaysShiverick
I didn't get it..But In Static typing we deliberately provide the data type. Could you provide some example pls for Inferred type?Mainsail
does the edit help you? else study the link to wikipedia I providedShiverick
K
1

you can change data type on the fly for dynamic typing, but inferred typing does not require explicit data type declaration before use.

Knothole answered 6/7, 2014 at 18:8 Comment(0)
M
0

Static and dynamic typing tell you when the type of the variables is checked. Static typing checks the type during compilation. Dynamic typing checks the type during runtime( on the fly)

Inferred and Manifest concerns whether you have to specify the type of the variable or not. Inferred means that the language will detect it for you. Manifest means that the type must be specified.

Moynahan answered 3/10, 2018 at 21:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.