CSC/ECE 517 Fall 2009/wiki1b 2 ps: Difference between revisions
No edit summary |
|||
Line 6: | Line 6: | ||
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. | The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. | ||
== Type Checking == | == Type Checking == | ||
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages. | |||
== Statically typed languages == | == Statically typed languages == | ||
=== Advantages and Disadvantages === | === Advantages and Disadvantages === |
Revision as of 05:33, 21 September 2009
Advantages of statically typed vs. dynamically typed languages
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the type system, the programming languages are classified as statically typed or dynamically typed. The statically typed languages like C, C++, C#, Java, FORTRAN etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like PHP, Prolog, Python, Ruby, Smalltalk etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].
Typed and Untyped languages
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].
Type Checking
Type checking is done only for the typed languages. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the type systems. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.
Statically typed languages
Advantages and Disadvantages
Dynamically typed languages
Advantages and Disadvantages
Comparison of statically typed and dynamically typed languages
References
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf