Three major components in a programming language
Data storage of an actual computer
-- Memory, register or external media
-- Usually have simple structure as sequence of bits comprising bytes or words
Data storage of a virtual computer
-- Arrays, stacks, numbers, character strings
In C) arrays
int arr[10]={1,2,3,4,5,6,7,8,9,10};
char arr2[12]="hello world";
-- Usually have more complex organization
In C) structure
struct info{
int number;
int age;
char name[4]; } person;
Data Object
-- Run-time grouping of one or more pieces of data in a virtual computer
-- Some are defined by programmer (variables, constants, arrays) and others are defined by system for house keeping(activation records)
-- Container for a data value (a single number, character or a memory location)
-- Classified as elementary object (manipulated as a single unit) or structured object (aggregated)
-- Each data object has a lifetime (extent)
Attributes associated with a data object
-- Name: Represent the object and is referred during execution time (N, M)
-- Type: Specify the data values that the object may contain (int, char)
-- Location: Address of the storage where the object is located (0x3a789b85)
-- Value: Actual value that the object containes (30, 20)
-- Component: The binding of a data object to one or more data objects (S[10])
-- Operations: Mechanisms to manipulate the object (+, -)
Variable
-- A data object that is defined and named by programmer explicitly in a program
-- The content(value) of a variable can be changed during its life time
-- Simple variable : an elementary data object with a name
-- Complex variable : group of variables
Constant
-- A data object with a name which is bound to a value permanently during its lifetime
-- Types of constants
-- Literal : representation is the written representation of the value
-- Programmer defined constant : name is chosen by the programmer
Data type
: A class of data objects together with a set of operations for creation and manipulation
: Examples of types are array, integer, file, float, etc.
-- Classes of data type
-- Primitive data type: built into the language
-- User-defined data type: with facilities that the language provides
-- Self-modifying types: content of data object is modified without programmer's control
-- Specification and Implementation of data types
-- Specification : a way of specifying defined data type as an object with attributes, values and operations
-- Implementation : a way of simulating defined data type on the virtual computer wirh representation and algorithm
Specification
-- Attributes: that distinguish data objects of that type
ex) Number of dimensions, subject range, data type of components
-- Values: that data objects of that type may have
ex) Set of numbers
-- Operations: that define the possible manipulations of data objects of that type
ex) consider array data type
Subscribing to select a component, create array, change shape, access attributes, and perform arithmetic on a pair of array
Implementation
-- Storage representation: used to represent the data object of that type (integer is stored in a word)
-- Algorithm: manner in which the operations are defined to manipulate the data object(procedures)
Subtype (subtype polymorphism)
-- a form in which a datatype is related to another datatype (the super type)
-- program elements, typically subroutines or functions, written to operate on elements of the supertype can also operate on elements of the subtype
-- Time & Space complexity are reduced
Implementation of elementary data types
-- Storage representation for data objects and values of that type
-- Strongly influenced on underlying hardware (efficient)
-- Sometimes it is software simulated(inefficient)
-- Data attributes are determined by compiler in many languages or sometimes data attributes are stored in a descriptor vector (e.g. LISP)
-- Set of algorithms or procedures that defines the operations of the type
-- Directly implemented by hardware
-- As a procedure or function subprogram
-- As in-line code sequence
Declarations
-- Definition
: Statements that specify information about the name, type of data object, and lifetime of each object
-- Explicit declaration vs. Implicit (default) declaration
-- Declaration of operations can be done by the signature of each operation
Purpose of declaration
Type safe system
: A function cannot generate result with a type outside of the signature
Type inference
-- Types can be resolved from the program by how they are used
-- Ex) fun area (length : int, width: int)
int= length*width
Type conversion
-- Takes one type and produce the corresponding type
-- Explicit type conversion by using a set of built-in functions
-- Implicit type conversion (type coercion = 묵시적형변환) as specified in the language
-- Basic principle is "not to lose information" called widening, or promotion
ex) Convert 118.625 (Decimal number) in IEEE 754 format
(1) Sign bit = 1
(2) Convert it to binary number : 1110110.101
(3) Left shift to make 1110110.101 = 1. 110110101 x 2^6 : Floating poing number
(4) Padding with 0's to make 23 bits : 110 1101 0100 0000 0000 0000
(5) Exponent is 6, thus add bias (127) and add 6 + 127 = 133 (1000 0101)
Specification
-- Digit sequence of fixed length
-- Avoid round-off errors (e.g. dollar and cents)
-- Scale factor
Implementation
-- Either supported by hardware or simulated by software
-- Calcultation is done after converting the numbers in the same format
Fascinating read on data types and type checking! The nuances between floating-point and fixed-point were particularly enlightening. For those looking to apply these concepts in web development, check out this helpful guide on the best programming languages for web development https://attractgroup.com/blog/best-programming-languages-for-web-development-and-where-to-get-custom-web-development-services/ , which also covers where to find bespoke services. A great resource to complement your learning!
Solid breakdown of data type specification and type checking in programming languages! It's crucial to understand these concepts for robust code. On a related note, I found an interesting article on healthcare data storage that delves into the challenges and solutions in safeguarding sensitive health information: https://www.cleveroad.com/blog/healthcare-data-storage/. It might add another layer to your exploration of data-related topics!