2. What is Data Type ?
For humans in their daily life it is easy to distinguish among different types of data they
come across eg. if number is a percentage or a time, or a weight, or an amount of
money. We do this through special symbols like %, :,kg, and $ that indicate the type of
information we are referring to Similarly, a computer program needed special internal
codes to keep track of the different types of data it is interacting with .
In computer science and computer programming, a data type or simply type is a classification identifying one of
various types of data, such as real, integer or Boolean, that determines the possible values for that type, the
operations that can be done on values of that type, the meaning of the data, and the way values of that type can be
stored “Wikipedia”
3. What purpose they Solve ?
In real Life we come across multiple type of statistical values like fractional data,count
data,positive or negative data,categorical data,lists,words,alphabets,matrices.
In a software code we define interfaces between different parts of a software code to be
connected in a consistent way to interact with such informations or data and to interchange
among themselves.
The consistency gets evaluated(Type Enforcement) strategically either at compile time or
at runtime of the code. With a consistent(the possible values for that type, the operations that can be
done on values of that type) data types structs makes life alot easier for a software developer to
stay aligned with the Type safety.
4. Type Enforcement
Type Enforcement is closely related to the Access control of the operating Systems which
can be defined as the selective restriction in turn it allows the code to access the memory
locations it is authorized to access.
For example :
an object can not read values from other objects private members.
5. Type Safety
Well-typed programs cannot "go wrong” Robin Miller
The behaviors classified as type errors by a given programming language are usually those that result from attempts
to perform operations on values that are not of the appropriate data type. “Wikipedia”
Type safety a restriction on the ability to copy arbitrary bit patterns from one memory
location to another . That may cause buffer overflow and dangling pointers .
Think if we could allow an arbitrary integer to be used as
a pointer
catastrophic
failure
7. Primitive Data Types
Characters,Integers, Floating point Numbers,Fixed Point Numbers ,Booleans, Characters,
Strings, References, Tuples,List,Complex Numbers,Functions,Rational Numbers.
A basic type is a data type provided by a programming language as a basic building block. Most languages allow
more complicated composite types to be recursively constructed starting from basic types.
A built-in type is a data type for which the programming language provides built-in support.
“Wikipedia”
8. Composite Data Types
An array stores a number of elements of the same type in a specific order.
Record ,tuple or struct is a value that contains other values, typically in fixed number
and sequence and typically indexed by names.
Union. A union type definition will specify which of a number of permitted primitive
types may be stored in its instances, e.g. "float or long integer". Contrast with a
record, which could be defined to contain a float and an integer; whereas, in a union,
there is only one type allowed at a time.
9. A tagged union (also called a variant, variant record, discriminated union, or disjoint
union) contains an additional field indicating its current type
A set is an abstract data structure that can store certain values, without any particular
order, and no repeated values.
An object contains a number of data fields, like a record, and also a number of
subroutines for accessing or modifying them, called methods.
“Wikipedia”