CSC/ECE 517 Fall 2009/wiki1b 2 SD: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
== Type System ==
== Type System ==


The formal definition of a type system is [1]:
The formal definition of a type system is [1] <ref> Pierce, B. C., & NetLibrary, I. (2002). Types and programming languages. Cambridge, Mass.: MIT Press. </ref>:


<center>''“A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute.”''</center>
<center>''“A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute.”''</center>


Type system is the study of types which defines the interaction between various types, the way in which a programming language assigns types. Type systems help detecting errors in the program, provide abstraction, improve the readability of the program, and improve the efficiency of the program [1], [2]. Detecting errors related to types in a program is called type checking.
Type system is the study of types which defines the interaction between various types, the way in which a programming language assigns types. Type systems help detecting errors in the program, provide abstraction, improve the readability of the program, and improve the efficiency of the program <ref>Pierce, B. C., & NetLibrary, I. (2002). Types and programming languages. Cambridge, Mass.: MIT Press.  </ref>, [2] <ref>http://www.ljosa.com/~ljosa/teaching/cs162/lectures/L7%20-%20Types.pdf </ref>. Detecting errors related to types in a program is called type checking.




Line 28: Line 28:


== References: ==
== References: == <references/>


[1] Pierce, B. C., & NetLibrary, I. (2002). Types and programming languages. Cambridge, Mass.: MIT Press.  
[1] Pierce, B. C., & NetLibrary, I. (2002). Types and programming languages. Cambridge, Mass.: MIT Press.  
[2] http://www.ljosa.com/~ljosa/teaching/cs162/lectures/L7%20-%20Types.pdf
[2] http://www.ljosa.com/~ljosa/teaching/cs162/lectures/L7%20-%20Types.pdf

Revision as of 20:45, 19 September 2009

Advantages of statically typed vs. dynamically typed languages

Type System

The formal definition of a type system is [1] <ref> Pierce, B. C., & NetLibrary, I. (2002). Types and programming languages. Cambridge, Mass.: MIT Press. </ref>:

“A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute.”

Type system is the study of types which defines the interaction between various types, the way in which a programming language assigns types. Type systems help detecting errors in the program, provide abstraction, improve the readability of the program, and improve the efficiency of the program <ref>Pierce, B. C., & NetLibrary, I. (2002). Types and programming languages. Cambridge, Mass.: MIT Press. </ref>, [2] <ref>http://www.ljosa.com/~ljosa/teaching/cs162/lectures/L7%20-%20Types.pdf </ref>. Detecting errors related to types in a program is called type checking.


Type Checking

In layman terms type checking is the process of determining errors related to types in the expressions and calculations of a program. There are a few programming languages which are typed and there are a few which are untyped. Among the typed programming languages, based on when the type checking happens, they are either dynamically typed or statically typed. There is another factor used to classify programming languages, that is, the level to which type checking is enforced. Based on the extent to which type checking is enforced, programming languages are either strongly typed or weakly typed. Therefore, broadly we classify programming languages as: - Statically typed: Type checking done at compile time. - Dynamically typed: - Strongly typed: - Weakly typed: Weak typing means that the language does implicit type casting. For e.g. consider the following operations: var a = 5; var b = “string”; var c = a + b; print c; We know that 5 is an integer and the type of ‘a’ is integer, which is different from the type of ‘b’ which is a string. Therefore, the operation a + b, should not have any value. In a weakly typed programming language, the result might be ‘5string’; this is because ‘a’ is implicitly converted into a string e.g. assembly languages, type errors cause erroneous calculation.


== References: == <references/>

[1] Pierce, B. C., & NetLibrary, I. (2002). Types and programming languages. Cambridge, Mass.: MIT Press. [2] http://www.ljosa.com/~ljosa/teaching/cs162/lectures/L7%20-%20Types.pdf