HOME

TheInfoList




In
imperative programming In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , ...
, a computer program is a sequence of instructions in a
programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (formal), letters are taken from an alphabet (computer science) ...

programming language
that a
computer A computer is a machine that can be programmed to Execution (computing), carry out sequences of arithmetic or logical operations automatically. Modern computers can perform generic sets of operations known as Computer program, programs. These ...

computer
can execute or interpret. In
declarative programming In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , ...
, a ''computer program'' is a set of instructions. A computer program in its human-readable form is called
source code In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...

source code
. Source code needs another computer program to execute because computers can only execute their native
machine instructions In computer programming, machine code, consisting of machine language instruction set, instructions, is a low-level programming language used to directly control a computer's central processing unit (CPU). Each instruction causes the CPU to perf ...
. Therefore, source code may be translated to machine instructions using the language's
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily ...

compiler
. (
Machine language In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, ...
programs are translated using an
assembler Assembler may refer to: Arts and media * Nobukazu Takemura Nobukazu Takemura (竹村延和 ''Takemura Nobukazu'') is a Japanese musician and artist. Born in Hirakata, Osaka in August 1968, he became interested in music at a young age by listenin ...

assembler
.) The resulting file is called an
executable In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...
. Alternatively, source code may execute within the language's interpreter. The programming language
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 147.7 million people, Java is the world's List of ...
compiles into an
a intermediate form
a intermediate form
which is then executed by a Java interpreter. If the executable is requested for execution, then the
operating system An operating system (OS) is system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android (operating system), Android and Mi ...

operating system
loads it into
memory Memory is the faculty of the brain A brain is an organ Organ may refer to: Biology * Organ (anatomy) An organ is a group of Tissue (biology), tissues with similar functions. Plant life and animal life rely on many organs that co-exis ...
and starts a
process A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic. Things called a process include: Business and management *Business process A business process, business method ...
. The
central processing unit A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuit 200px, A circuit built on a printed circuit board (PCB). An electronic circuit is composed of individual electroni ...

central processing unit
will soon
switch In electrical engineering Electrical engineering is an engineering discipline concerned with the study, design, and application of equipment, devices, and systems which use electricity, electronics The field of electronics is a branch of p ...
to this process so it can fetch, decode, and then execute each machine instruction. If the source code is requested for execution, then the operating system loads the corresponding interpreter into memory and starts a process. The interpreter then loads the source code into memory to translate and execute each statement. Running the source code is slower than running an executable. Moreover, the interpreter must be installed on the computer.


History


Analytical Engine

In 1837,
Charles Babbage Charles Babbage (; 26 December 1791 – 18 October 1871) was an English polymath A polymath ( el, πολυμαθής, , "having learned much"; la, homo universalis, "universal human") is an individual whose knowledge spans a subs ...

Charles Babbage
was inspired by Jacquard's loom to attempt to build the
Analytical Engine The Analytical Engine was a proposed mechanical general-purpose computer A computer is a machine A machine is a man-made device that uses power to apply forces and control movement to perform an action. Machines can be driven by ...
. The names of the components of the calculating device were borrowed from the textile industry. In the textile industry, yarn was brought from the store to be milled. The device had a "store" which was memory to hold 1,000 numbers of 40 decimal digits each. Numbers from the "store" were transferred to the "mill" for processing. It was programmed using two sets of perforated cards. One set to direct the operation and the other for the input variables. However, after more than 17,000 pounds of the British government's money, the thousands of cogged wheels and gears never fully worked together. During a nine-month period in 1842–43, Ada Lovelace translated the memoir of Italian mathematician Luigi Menabrea. The memoir covered the Analytical Engine. The translation contained Note G which completely detailed a method for calculating Bernoulli numbers using the Analytical Engine. This note is recognized by some historians as the world's first written computer program.


Universal Turing machine

In 1936, Alan Turing introduced the Universal Turing machine—a theoretical device that can model every computation that can be performed on a Turing complete computing machine. It is a finite-state machine that has an infinitely long read/write tape. The machine can move the tape back and forth, changing its contents as it performs an algorithm. The machine starts in the initial state, goes through a sequence of steps, and halts when it encounters the halt state.


Relay-based computers

The Z3 (computer), Z3 computer, invented by Konrad Zuse (1941), was a digital and programmable computer. Zuse became aware of the "Babbage Engine" in 1939 while attempting to file a Germany, German patent. The ''Analytical Engine'' was base-10 — which was easy to comprehend. Zuse recognized that a Binary code, binary machine was easy to construct. Relay, Telephone relays are two-position switches — open or closed. The Z3 had approximately 2,600 relays: 1,800 for the memory, 600 for the arithmetic, and 200 for the punched tape, punch tape reader, keyboard, and display. The circuits provided a floating-point, nine-instruction computer. Programming the Z3 was through a specially designed keyboard and punch tape. Manual input was through a calculator-style keyboard that accepted decimal numbers. The machine converted the input to binary and passed them through a series of calculating modules. The result was converted back to decimal and displayed on an output panel. Simultaneously developed was its successor — the Z4 (computer), Z4 computer. (An air-raid on April 6, 1945 destroyed the Z3.) In 1950, the Z4 was placed into production at the ETH Zurich, Federal Technical Institute in Zurich. It pioneered the short tenure of relay-based computers.


ENIAC

The ENIAC, Electronic Numerical Integrator And Computer (ENIAC) was built between July 1943 and Fall 1945. It was a Turing complete, general-purpose computer that used 17,468 vacuum tubes to create the Electronic circuit, circuits. At its core, it was a series of Pascalines wired together. Its 40 units weighed 30 tons, occupied , and consumed $650 per hour (Inflation, in 1940s currency) in electricity when idle. It had 20 base-10 Accumulator (computing), accumulators. Programming the ENIAC took up to two months. Three function tables were on wheels and needed to be rolled to fixed function panels. Function tables were connected to function panels using heavy black cables. Each function table had 728 rotating knobs. Programming the ENIAC also involved setting some of the 3,000 switches. Debugging a program took a week. It ran from 1947 until 1955 at Aberdeen Proving Ground, calculating hydrogen bomb parameters, predicting weather patterns, and producing firing tables to aim artillery guns.


Stored-program computers

Instead of plugging in cords and turning switches, a stored-program computer loads its instructions into memory just like it loads its data into memory. As a result, the computer could be programmed quickly and perform calculations at very fast speeds. J. Presper Eckert, Presper Eckert and John Mauchly built the ENIAC. The two engineers introduced the ''stored-program concept'' in a three-page memo dated February 1944. Later, in September 1944, John von Neumann, Dr. John von Neumann began working on the ENIAC project. On June 30, 1945, von Neumann published the ''First Draft of a Report on the EDVAC'' which equated the structures of the computer with the structures of the human brain. The design became known as the von Neumann architecture. The architecture was simultaneously deployed in the constructions of the EDVAC and EDSAC computers in 1949. In 1961, the Burroughs large systems#B5000, Burroughs B5000 was built specifically to be programmed in the ALGOL 60, Algol 60 language. The hardware featured circuits to ease the compiler, compile phase. In 1964, the IBM System/360 was a line of six computers each having the same instruction set, instruction set architecture. The IBM System/360 Model 30, Model 30 was the smallest and least expensive. Customers could upgrade and retain the same application software. The IBM System/360 Model 75, Model 75 was the most premium. Each System/360 model featured Computer multitasking#Multiprogramming, multiprogramming — having multiple Process (computing), processes in random-access memory, memory at once. When one process was waiting for input/output, another could compute. IBM planned for each model to be programmed using PL/1. A committee was formed that included COBOL, Fortran and ALGOL programmers. The purpose was to develop a language that was comprehensive, easy to use, extendible, and would replace Cobol and Fortran. The result was a large and complex language that took a long time to Compiler, compile. Computers manufactured until the 1970s had front-panel switches for manual programming. The computer program was written on paper for reference. An instruction was represented by a configuration of on/off settings. After setting the configuration, an execute button was pressed. This process was then repeated. Computer programs also were automatically inputted via paper tape or punched cards. After the medium was loaded, the starting address was set via switches, and the execute button was pressed.


Programming languages

Computer programming (also known as software development and software engineering) is the process of writing or editing
source code In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...

source code
. In a formal environment, a systems analyst will gather information from managers about all the business processes to automate. This professional then prepares a detailed plan for the new or modified system. The plan is analogous to an architect's blueprint. A computer programmer is a specialist responsible for writing or modifying the source code to implement the detailed plan. A
programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (formal), letters are taken from an alphabet (computer science) ...

programming language
is a set of Reserved word, keywords, Character (computing), symbols, Identifier (computer languages), identifiers, and rules by which programmers can communicate instructions to the computer. They follow a set of rules called a Syntax (programming languages), syntax. * ''Keywords'' are reserved words to form Declaration (computer programming), declarations and Statement (computer science), statements. * ''Symbols'' are characters to form Operation (mathematics), operations, Assignment (computer science), assignments, control flow, and Delimiter, delimiters. * ''Identifiers'' are words created by programmers to form Constant (computer programming), constants, Variable (computer science), variable names, Record (computer science), structure names, and Subroutine#functions, function names. * ''Syntax Rules'' are defined in the Backus–Naur form. ''Programming languages'' get their basis from formal language, formal languages. The purpose of defining a solution in terms of its ''formal language'' is to generate an algorithm to solve the underlining problem. An ''algorithm'' is a sequence of simple instructions that solve a problem.


Generation of programming languages

The evolution of programming languages began when the EDSAC (1949) used the first Stored-program computer, stored computer program in its von Neumann architecture. Programming the EDSAC was in the first Programming language generations, generation of programming languages. * The First-generation programming language, first generation of programming languages is machine language. ''Machine language'' requires the programmer to enter instructions using ''instruction numbers'' called machine code. For example, the ADD operation on the PDP-11 has instruction number 24576. * The Second-generation programming language, second generation of programming languages is assembly language. ''Assembly language'' allows the programmer to use Assembly_language#Mnemonics, mnemonic instructions instead of remembering instruction numbers. An Assembly_language#Assembler, assembler translates each assembly language mnemonic into its machine language number. For example, on the PDP-11, the operation 24576 can be referenced as ADD in the source code. The four basic arithmetic operations have assembly instructions like ADD, SUB, MUL, and DIV. Computers also have instructions like DW (Define Word (computer architecture), Word) to reserve
memory Memory is the faculty of the brain A brain is an organ Organ may refer to: Biology * Organ (anatomy) An organ is a group of Tissue (biology), tissues with similar functions. Plant life and animal life rely on many organs that co-exis ...
cells. Then the MOV instruction can copy Integer, integers between Processor register, registers and memory. :* The basic structure of an assembly language statement is label, operation, operand, and comment. ::* ''Labels'' allow the programmer to work with Variable (computer science), variable names. The assembler will later translate labels into physical memory address, memory addresses. ::* ''Operations'' allow the programmer to work with mnemonics. The assembler will later translate mnemonics into instruction numbers. ::* ''Operands'' tell the assembler which data the operation will process. ::* ''Comments'' allow the programmer to articulate a narrative because the instructions alone are vague. :: The key characteristic of an assembly language program is it forms a one-to-one mapping to its corresponding machine language target. * The Third-generation programming language, third generation of programming languages use Compiler, compilers and Interpreter (computing), interpreters to execute computer programs. Unlike assembly language, these languages generate many machine language instructions for each symbolic statement. The distinguishing feature of ''third generation'' languages is their independence from a particular hardware. They began with the languages of Fortran (1958), COBOL (1959), ALGOL (1960), and BASIC (1964). In 1973, C (programming language), C emerged as a high-level language that produced efficient machine language instructions. Today, an entire programming paradigm, paradigm of languages fill the imperative programming, imperative ''third generation'' spectrum. * The Fourth-generation programming language, fourth generation of programming languages emphasize what output results are desired, rather than how programming statements should be constructed. Declarative programming, Declarative languages attempt to limit Side effect (computer science), side effects and allow programmers to write code with relatively few errors. One popular ''fourth generation'' language is called SQL, Structured Query Language (SQL). Database developers no longer need to process each database record one at a time. Also, a simple instruction can generate output records without having to understand how it's retrieved. * The Fifth-generation programming language, fifth generation of programming languages use visual tools to generate source code. An integrated development environment allows the programmer to draw the graphical user interface (GUI) on the screen using a Computer mouse, mouse. The programmer writes Event (computing), event handling Subroutine#Functions, functions that will be executed when Field (computer science), fields are hovered over, entered into, or exited from. The development system couples the functions to the GUI and outputs a ''computer program''.


Imperative languages

''Imperative languages'' specify a sequential algorithm#Computer algorithm, algorithm using declarations, expressions, and statements: * A ''Declaration (computer programming), declaration'' introduces a variable (programming), variable name to the ''computer program'' and assigns it to a datatype – for example: var x: integer; * An ''Expression (computer science), expression'' yields a value – for example: 2 + 2 yields 4 * A ''Statement (computer science), statement'' might Assignment (computer science), assign an expression to a variable or use the value of a variable to alter the program's control flow – for example: x := 2 + 2; Conditional_(computer_programming)#If–then(–else), if x = 4 then do_something();


Fortran

FORTRAN (1958) was unveiled as "The IBM Mathematical FORmula TRANslating system." It first compiled correctly in 1958. It was designed for scientific calculations, without String (computer science), string handling facilities. Along with ''declarations'', ''expressions'' and ''statements'', it supported: * Array data structure, arrays. * Subroutine, subroutines. * For loop, "do" loops. It succeeded because: * programming and debugging costs were below computer running costs. * it was supported by IBM. * applications at the time were scientific. However, non IBM vendors also wrote Fortran compilers, but with a syntax that would likely fail IBM's compiler. The American National Standards Institute (ANSI) developed the first Fortran standard in 1966. In 1978, Fortran 77 became the standard until 1991. Fortran 90 supports: * Record (computer science), records. * Pointer (computer programming), pointers to arrays.


COBOL

COBOL (1959) stands for "COmmon Business Oriented Language." Fortran manipulated symbols. It was soon realized that symbols didn't need to be numbers, so strings were introduced. The US Department of Defense influenced COBOL's development, with Grace Hopper being a major contributor. The statements were English-like and verbose. The goal was to design a language so managers could read the programs. However, the lack of structured statements hindered this goal. COBOL's development was tightly controlled, so dialects didn't emerge to require ANSI standards. As a consequence, it wasn't changed for 25 years until 1974. The 1990s version did make consequential changes like object-oriented programming.


Algol

ALGOL (1960) stands for "ALGOrithmic Language." It had a profound influence on programming language design. Emerging from a committee of European and American programming language experts, it used standard mathematical notation and had a readable structured design. Algol was first to define its Syntax (programming languages), syntax using the Backus–Naur form. This led to Syntax-directed translation, syntax-directed compilers. It added features like: * block structure, where variables were local to their block. * arrays with variable bounds. * For loop, "for" loops. * Subroutine#Functions, functions. * Recursion (computer science), recursion. Algol's direct descendants include Pascal (programming language), Pascal, Modula-2, Ada (programming language), Ada, Delphi (software), Delphi and Oberon (programming language), Oberon on one branch. On another branch there's C (programming language), C, C++ and
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 147.7 million people, Java is the world's List of ...
.


Basic

BASIC (1964) stands for "Beginner's All Purpose Symbolic Instruction Code." It was developed at Dartmouth College for all of their students to learn. If a student didn't go on to a more powerful language, the student would still remember Basic. A Basic interpreter was installed in the microcomputers manufactured in the late 1970s. As the microcomputer industry grew, so did the language. Basic pioneered the Read–eval–print loop, interactive session. It offered
operating system An operating system (OS) is system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android (operating system), Android and Mi ...

operating system
commands within its environment: * The 'new' command created an empty slate. * Statements evaluated immediately. * Statements could be programmed by preceding them with a line number. * The 'list' command displayed the program. * The 'run' command executed the program. However, the Basic syntax was too simple for large programs. Recent dialects have added structure and object-oriented extensions. Microsoft, Microsoft's Visual Basic is still widely used and produces a graphical user interface.


C

C (programming language), C programming language (1973) got its name because the language BCPL was replaced with B (programming language), B, and Bell Labs, AT&T Bell Labs called the next version "C." Its purpose was to write the UNIX
operating system An operating system (OS) is system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android (operating system), Android and Mi ...

operating system
. C is a relatively small language -- making it easy to write compilers. Its growth mirrored the hardware growth in the 1980s. Its growth also was because it has the facilities of assembly language, but uses a High-level programming language, high-level syntax. It added advanced features like: * inline assembler. * arithmetic on pointers. * pointers to functions. * bit operations. * freely combining complex operators. ''C'' allows the programmer to control which region of memory data is to be stored. ''Global variables'' and ''static variables'' require the fewest Clock signal, clock cycles to store. The ''stack'' is automatically used for the standard variable declarations. ''Heap'' memory is returned to a ''pointer variable'' from the C dynamic memory allocation, malloc() function. * The ''global and static data'' region is located just above the ''program'' region. (The program region is technically called the ''text'' region. It's where machine instructions are stored.) :* The global and static data region is technically two regions. One region is called the ''initialized data segment'' where variables declared with default values are stored. The other region is called the ''.bss, block started by segment'' where variables declared without default values are stored. :* Variables stored in the ''global and static data'' region have their Memory address, addresses set at compile-time. They retain their values throughout the life of the process. :* The global and static region stores the ''global variables'' that are declared on top of (outside) the main() function. Global variables are visible to main() and every other function in the source code. : On the other hand, variable declarations inside of main(), other functions, or within Block (programming), block delimiters are ''local variables''. Local variables also include ''Parameter_(computer_programming)#Parameters_and_arguments, formal parameter variables''. Parameter variables are enclosed within the parenthesis of function definitions. They provide an Interface (computing), interface to the function. :* ''Local variables'' declared using the static prefix are also stored in the ''global and static data'' region. Unlike global variables, static variables are only visible within the function or block. Static variables always retain their value. An example usage would be the function int increment_counter() * The ''Stack-based memory allocation, stack'' region is a contiguous block of memory located near the top memory address. Variables placed in the stack, ironically, are populated from top to bottom. A Call_stack#STACK-POINTER, stack pointer is a special-purpose processor register, register that keeps track of the last memory address populated. Variables are placed into the stack via the ''assembly language'' PUSH instruction. Therefore, the addresses of these variables are set during Runtime (program lifecycle phase), runtime. The method for stack variables to lose their scope is via the POP instruction. :* ''Local variables'' declared without the static prefix, including formal parameter variables, are called ''automatic variables'' and are stored in the stack. They are visible inside the function or block and lose their scope upon exiting the function or block. * The ''heap'' region is located below the stack. It is populated from the bottom to the top. The
operating system An operating system (OS) is system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android (operating system), Android and Mi ...

operating system
manages the heap using a ''heap pointer'' and a list of allocated memory blocks. Like the stack, the addresses of heap variables are set during runtime. Out of memory errors occur when the heap pointer and the stack pointer meet. :* ''C'' provides the C dynamic memory allocation, malloc() library function to allocate heap memory. Populating the heap with data is an additional copy function. Variables stored in the heap are economically passed to functions using pointers. Without pointers, the entire block of data would need to be passed to the function via the stack.


C++

In the 1970s, software engineering, software engineers needed language support to break large projects down into Modular_programming, modules. One obvious feature was to decompose large projects ''physically'' into separate computer file, files. A less obvious feature was to decompose large projects ''logically'' into Abstract and concrete, abstract Data type, datatypes. At the time, languages supported concrete (Variable (computer science), scalar) datatypes like integer numbers, Floating-point arithmetic, floating-point numbers, and String (computer science), strings of Character (computing), characters. Concrete datatypes have their representation as part of their name. Abstract datatypes are Record (computer science), structures of concrete datatypes — with a new name assigned. For example, a List (abstract data type), list of integers could be called integer_list. In object-oriented jargon, abstract datatypes are called Class (computer programming), classes. However, a ''class'' is only a definition; no memory is allocated. When memory is allocated to a class, it's called an Object (computer science), object. ''Object-oriented programming, Object-oriented imperative languages'' developed by combining the need for classes and the need for safe functional programming. A function, in an object-oriented language, is assigned to a class. An assigned function is then referred to as a Method (computer programming), method, Method_(computer_programming)#Member_functions_in_C++, member function, or ''Operation (mathematics), operation''. ''Object-oriented programming'' is executing ''operations'' on ''objects''. ''Object-oriented languages'' support a syntax to model subset, subset/superset relationships. In set theory, an Element (mathematics), element of a subset inherits all the attributes contained in the superset. For example, a student is a person. Therefore, the set of students is a subset of the set of persons. As a result, students inherit all the attributes common to all persons. Additionally, students have unique attributes that other persons don't have. ''Object-oriented languages'' model ''subset/superset'' relationships using Inheritance (object-oriented programming), inheritance. ''Object-oriented programming'' became the dominant language paradigm by the late 1990s. C++ (1985) was originally called "C with Classes." It was designed to expand C (programming language), C's capabilities by adding the object-oriented facilities of the language Simula. An object-oriented module is composed of two files. The definitions file is called the Include directive, header file. Here is a C++ ''header file'' for the ''GRADE class'' in a simple school application: // grade.h // ------- // Used to allow multiple source files to include // this header file without duplication errors. // ---------------------------------------------- #ifndef GRADE_H #define GRADE_H class GRADE ; #endif A Constructor (object-oriented programming), constructor operation is a function with the same name as the class name. It is executed when the calling operation executes the new statement. A module's other file is the ''source file''. Here is a C++ source file for the ''GRADE class'' in a simple school application: // grade.cpp // --------- #include "grade.h" GRADE::GRADE( const char letter ) int GRADE::grade_numeric( const char letter ) Here is a C++ ''header file'' for the ''PERSON class'' in a simple school application: // person.h // -------- #ifndef PERSON_H #define PERSON_H class PERSON ; #endif Here is a C++ ''source code'' for the ''PERSON class'' in a simple school application: // person.cpp // ---------- #include "person.h" PERSON::PERSON ( const char *name ) Here is a C++ ''header file'' for the ''STUDENT class'' in a simple school application: // student.h // --------- #ifndef STUDENT_H #define STUDENT_H #include "person.h" #include "grade.h" // A STUDENT is a subset of PERSON. // -------------------------------- class STUDENT : public PERSON; #endif Here is a C++ ''source code'' for the ''STUDENT class'' in a simple school application: // student.cpp // ----------- #include "student.h" #include "person.h" STUDENT::STUDENT ( const char *name ): // Execute the constructor of the PERSON superclass. // ------------------------------------------------- PERSON( name ) Here is a driver program for demonstration: // student_dvr.cpp // --------------- #include #include "student.h" int main( void ) Here is a makefile to compile everything: # makefile # -------- all: student_dvr clean: rm student_dvr *.o student_dvr: student_dvr.cpp grade.o student.o person.o c++ student_dvr.cpp grade.o student.o person.o -o student_dvr grade.o: grade.cpp grade.h c++ -c grade.cpp student.o: student.cpp student.h c++ -c student.cpp person.o: person.cpp person.h c++ -c person.cpp


Declarative languages

''Imperative languages'' have one major criticism: assigning an expression to a ''non-local'' variable may produce an unintended Side effect (computer science), side effect. Declarative programming, Declarative languages generally omit the assignment statement and the control flow. They describe ''what'' computation should be performed and not ''how'' to compute it. Two broad categories of declarative languages are functional languages and Logic programming, logical languages. The principle behind a ''functional language'' is to use lambda calculus as a guide for a well defined Semantics (computer science), semantic. In mathematics, a function is a rule that maps elements from an ''expression'' to a range of ''values''. Consider the function: times_10(x) = 10 * x The ''expression'' 10 * x is mapped by the function times_10() to a range of ''values''. One ''value'' happens to be 20. This occurs when x is 2. So, the application of the function is mathematically written as: times_10(2) = 20 A ''functional language'' compiler will not store this value in a variable. Instead, it will ''push'' the value onto the computer's Call stack, stack before setting the Program counter, program counter back to the calling function. The calling function will then ''pop'' the value from the stack. ''Imperative languages'' do support functions. Therefore, ''functional programming'' can be achieved in an imperative language, if the programmer uses discipline. However, ''functional languages'' force this discipline onto the programmer through its syntax. Functional languages have a syntax tailored to emphasize the ''what''. A functional program is developed with a set of primitive functions followed by a single driver function. Consider the Snippet (programming), snippet: function max(a,b) function min(a,b) function difference_between_largest_and_smallest(a,b,c) The primitives are max() and min(). The driver function is difference_between_largest_and_smallest(). Executing: put(difference_between_largest_and_smallest(10,4,7)); will output 6. ''Functional languages'' are used in computer science research to explore new language features. Moreover, their lack of side-effects have made them popular in Parallel computing, parallel programming and Concurrent computing, concurrent programming. However, application developers prefer the object-oriented programming, object-oriented features of ''imperative languages''.


Lisp

Lisp (programming language), Lisp (1958) stands for "LISt Processor." It is tailored to process List (abstract data type), lists. A full structure of the data is formed by building lists of lists. In memory, a Tree (data structure), tree data structure is built. Internally, the tree structure lends nicely for Recursion (computer science), recursive functions. The syntax to build a tree is to enclose the space-separated Element (mathematics), elements within parenthesis. The following is a list of three elements. The first two elements are themselves lists of two elements: ((A B) (HELLO WORLD) 94) Lisp has functions to extract and reconstruct elements. The function head() returns a list containing the first element in the list. The function tail() returns a list containing everything but the first element. The function cons() returns a list that is the concatenation of other lists. Therefore, the following expression will return the list x: cons(head(x), tail(x)) One drawback of Lisp is when many functions are nested, the parentheses may look confusing. Modern Lisp Integrated development environment, environments help ensure parenthesis match. As an aside, Lisp does support the ''imperative language'' operations of the assignment statement and goto loops. Also, ''Lisp'' is not concerned with the data type, datatype of the elements at compile time. Instead, it assigns the datatypes at runtime. This may lead to programming errors not being detected early in the development process. Writing large, reliable, and readable Lisp programs requires forethought. If properly planned, the program may be much shorter than an equivalent ''imperative language'' program. ''Lisp'' is widely used in artificial intelligence. However, its usage has been accepted only because it has ''imperative language'' operations, making unintended side-effects possible.


ML

ML (programming language), ML (1973) stands for "Meta Language." ML checks to make sure only data of the same type are compared with one another. For example, this function has one input parameter (an integer) and returns an integer: fun times_10(n : int) : int = 10 * n; ''ML'' is not parenthesis-eccentric like ''Lisp''. The following is an application of times_10(): times_10 2 It returns "20 : int". (Both the results and the datatype are returned.) Like ''Lisp'', ''ML'' is tailored to process lists. Unlike ''Lisp'', each element is the same datatype.


Prolog

Prolog (1972) stands for "PROgramming in LOgic." It was designed to process natural languages. The building blocks of a Prolog program are ''Object (philosophy), objects'' and their ''relationships'' to other objects. ''Objects'' are built by stating true ''facts'' about them. Set (mathematics), Set theory ''facts'' are formed by assigning objects to sets. The syntax is setName(object). * Cat is an animal. : animal(cat). * Mouse is an animal. : animal(mouse). * Tom is a cat. : cat(tom). * Jerry is a mouse. : mouse(jerry). Adjective ''facts'' are formed using adjective(object). * Cat is big. : big(cat). * Mouse is small. : small(mouse). ''Relationships'' are formed using multiple items inside the parentheses. In our example we have verb(object,object) and verb(adjective,adjective). * Mouse eats cheese. : eat(mouse,cheese). * Big animals eat small animals. : eat(big,small). After all the facts and relationships are entered, then a question can be asked: : Will Tom eat Jerry? : ?- eat(tom,jerry). Prolog's usage has expanded to become a goal-oriented language. In a goal-oriented application, the goal is defined by providing a list of subgoals. Then each subgoal is defined by further providing a list of its subgoals, etc. If a path of subgoals fails to find a solution, then that subgoal is backtracking, backtracked and another path is systematically attempted. Practical applications include solving the shortest path problem and producing Family tree, family trees.


Program modules

Modular programming is a technique to refine ''imperative language'' programs. A ''program module'' is a sequence of statements that are bounded within a Block (programming), block and together identified by a name. Modules have a ''function'', ''context'', and ''logic'': * The ''function'' of a module is what it does. * The ''context'' of a module are the elements being performed upon. * The ''logic'' of a module is how it performs the function. The module's name should be derived first by its ''function'', then by its ''context''. Its ''logic'' should not be part of the name. For example, function compute_square_root( x ) or function compute_square_root_integer( i : integer ) are appropriate module names. However, function compute_square_root_by_division( x ) is not. The degree of interaction ''within'' a module is its level of Cohesion (computer science), cohesion. ''Cohesion'' is a judgement of the relationship between a module's name and its ''function''. The degree of interaction ''between'' modules is the level of Coupling (computer science), coupling. ''Coupling'' is a judgement of the relationship between a module's ''context'' and the elements being performed upon.


Cohesion

The levels of cohesion from worst to best are: * ''Coincidental Cohesion'': A module has coincidental cohesion if it performs multiple functions, and the functions are completely unrelated. For example, function read_sales_record_print_next_line_convert_to_float(). Coincidental cohesion occurs in practice if management enforces silly rules. For example, "Every module will have between 35 and 50 executable statements." * Logical Cohesion: A module has logical cohesion if it has available a series of functions, but only one of them is executed. For example, function perform_arithmetic( perform_addition ). * ''Temporal Cohesion'': A module has temporal cohesion if it performs functions related to time. One example, function initialize_variables_and_open_files(). Another example, stage_one(), stage_two(), ... * ''Procedural Cohesion'': A module has procedural cohesion if it performs multiple functions, but only loosely related. For example, function read_part_number_update_employee_record(). * ''Communicational Cohesion'': A module has communicational cohesion if it performs multiple functions, but closely related. For example, function read_part_number_update_sales_record(). * ''Informational Cohesion'': A module has informational cohesion if it performs multiple functions, but each function has its own entry and exit points. Moreover, the functions share the same data structure. Object-oriented classes work at this level. * ''Functional Cohesion'': a module has functional cohesion if it achieves a single goal working only on local variables. Moreover, it may be reusable in other contexts.


Coupling

The levels of coupling from worst to best are: * ''Content Coupling'': A module has content coupling if it modifies a local variable of another function. COBOL used to do this with the ''alter'' verb. * ''Common Coupling'': A module has common coupling if it modifies a global variable. * ''Control Coupling'': A module has control coupling if another module can modify its control flow. For example, perform_arithmetic( perform_addition ). Instead, control should be on the makeup of the returned object. * ''Stamp Coupling'': A module has stamp coupling if an element of a data structure passed as a parameter is modified. Object-oriented classes work at this level. * '' Data Coupling'': A module has data coupling if all of its input parameters are needed and none of them are modified. Moreover, the result of the function is returned as a single object.


Data flow analysis

''Data flow analysis'' is a design method used to achieve modules of ''functional cohesion'' and ''data coupling''. The input to the method is a data-flow diagram. A data-flow diagram is a set of ovals representing modules. Each module's name is displayed inside its oval. Modules may be at the executable level or the function level. The diagram also has arrows connecting modules to each other. Arrows pointing into modules represent a set of inputs. Each module should have only one arrow pointing out from it to represent its single output object. (Optionally, an additional exception arrow points out.) A Daisy chain (electrical engineering), daisy chain of ovals will convey an entire algorithm. The input modules should start the diagram. The input modules should connect to the transform modules. The transform modules should connect to the output modules.


Object-oriented programming

Object-oriented programming need not be confined to an ''object-oriented language''. ''Object-oriented programming'' is executing ''operations'' on ''objects''. In object-oriented languages, classes are objects. In non-object-oriented languages, data structures (which are also known as Record (computer science), records) may also be objects. To turn a data structure into an object, operations need to be written specifically for the structure. The resulting structure is called an ''abstract datatype''. However, Inheritance (object-oriented programming), inheritance will be missing. Nonetheless, this shortcoming can be overcome. Here is a C programming language ''header file'' for the ''GRADE abstract datatype'' in a simple school application: /* grade.h */ /* ------- */ /* Used to allow multiple source files to include */ /* this header file without duplication errors. */ /* ---------------------------------------------- */ #ifndef GRADE_H #define GRADE_H typedef struct GRADE; /* Constructor */ /* ----------- */ GRADE *grade_new( char letter ); int grade_numeric( char letter ); #endif The grade_new() function performs the same algorithm as the C++ Constructor (object-oriented programming), constructor operation. Here is a C programming language source file for the ''GRADE abstract datatype'' in a simple school application: /* grade.c */ /* ------- */ #include "grade.h" GRADE *grade_new( char letter ) int grade_numeric( char letter ) In the constructor, the function calloc() is used instead of malloc() because each memory cell will be set to zero. Here is a C programming language ''header file'' for the ''PERSON abstract datatype'' in a simple school application: /* person.h */ /* -------- */ #ifndef PERSON_H #define PERSON_H typedef struct PERSON; /* Constructor */ /* ----------- */ PERSON *person_new( char *name ); #endif Here is a C programming language ''source code'' for the ''PERSON abstract datatype'' in a simple school application: /* person.c */ /* -------- */ #include "person.h" PERSON *person_new( char *name ) Here is a C programming language ''header file'' for the ''STUDENT abstract datatype'' in a simple school application: /* student.h */ /* --------- */ #ifndef STUDENT_H #define STUDENT_H #include "person.h" #include "grade.h" typedef struct STUDENT; /* Constructor */ /* ----------- */ STUDENT *student_new( char *name ); #endif Here is a C programming language ''source code'' for the ''STUDENT abstract datatype'' in a simple school application: /* student.c */ /* --------- */ #include "student.h" #include "person.h" STUDENT *student_new( char *name ) Here is a driver program for demonstration: /* student_dvr.c */ /* ------------- */ #include #include "student.h" int main( void ) Here is a makefile to compile everything: # makefile # -------- all: student_dvr clean: rm student_dvr *.o student_dvr: student_dvr.c grade.o student.o person.o gcc student_dvr.c grade.o student.o person.o -o student_dvr grade.o: grade.c grade.h gcc -c grade.c student.o: student.c student.h gcc -c student.c person.o: person.c person.h gcc -c person.c The formal strategy to build object-oriented objects is to: * Identify the objects. Most likely these will be nouns. * Identify each object's attributes. What helps to describe the object? * Identify each object's actions. Most likely these will be verbs. * Identify the relationships from object to object. Most likely these will be verbs. For example: * A person is a human identified by a name. * A grade is an achievement identified by a letter. * A student is a person who earns a grade.


Functional categories

Computer programs may be categorized along functional lines. The main functional categories are application software and system software. System software includes the
operating system An operating system (OS) is system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android (operating system), Android and Mi ...

operating system
which couples computer hardware with application software. The purpose of the operating system is to provide an environment where application software executes in a convenient and efficient manner. In addition to the operating system, system software includes Firmware, embedded programs, Booting, boot programs, and Microcode, micro programs. Application software designed for end users have a Interface (computing), user interface. Application software not designed for end users includes middleware, which couples one application with another. Both system software and application software execute Utility software, utility programs.


Application software

Application software is the key to unlocking the potential of the computer system. Enterprise software, Enterprise application software bundles accounting, personnel, customer, and vendor applications. Examples include enterprise resource planning, customer relationship management, and supply chain management software. Enterprise applications may be developed in-house as a one-of-a-kind proprietary software. Alternatively, they may be purchased as Commercial off-the-shelf, off-the-shelf software. Purchased software may be modified to provide custom software. If the application is customized, then either the company's resources are used or the resources are outsourced. Outsourced software development may be from the original software vendor or a third-party developer. The advantages of proprietary software are features and reports may be exact to specification. Management may also be involved in the development process and offer a level of control. Management may decide to counteract a competitor's new initiative or implement a customer or vendor requirement. A merger or acquisition will necessitate enterprise software changes. The disadvantages of proprietary software are the time and resource costs may be extensive. Furthermore, risks concerning features and performance may be looming. The advantages of off-the-shelf software are its identifiable upfront costs, the basic needs should be fulfilled, and its performance and reliability have a track record. The disadvantages of off-the-shelf software are it may have unnecessary features that confuse end users, it may lack features the enterprise needs, and the data flow may not match the enterprise's work processes. One approach to economically obtaining a customized enterprise application is through an Application service provider, application service provider. Specialty companies provide the hardware, custom software, and end-user support. They may speed development of new applications because they possess skilled information system staff. The biggest advantage is it frees in-house resources from staffing and managing complex computer projects. Many application service providers target small, fast-growing companies with limited information system resources. On the other hand, larger companies with major systems will likely have their technical infrastructure in place. One risk is having to trust an external organization with sensitive information. Another risk is having to trust the provider's infrastructure reliability.


Operating system

An
operating system An operating system (OS) is system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android (operating system), Android and Mi ...

operating system
is the low-level software that supports a computer's basic functions, such as Scheduling (computing), scheduling tasks and controlling Peripheral, peripherals. In the 1950s, the programmer, who was also the operator, would write a program and run it. After the program finished executing, the output may have been printed, or it may have been punched onto paper tape or cards for later processing. More often than not the program did not work. The programmer then looked at the console lights and fiddled with the console switches. If less fortunate, a memory printout was made for further study. In the 1960s, programmers reduced the amount of wasted time by automating the operator's job. A program called an ''operating system'' was kept in the computer at all times. The term ''operating system'' may refer to two levels of software. The operating system may refer to the Kernel (operating system), kernel program that manages the Process (computing), processes, Computer memory, memory, and Peripheral, devices. More broadly, the operating system may refer to the entire package of the central software. The package includes a kernel program, Command-line interface, command-line interpreter, Graphical user interface, graphical user interface, Utility software, utility programs, and Text editor, editor. * The kernel program should perform Scheduling (computing), process scheduling. The kernel creates a process control block when a program is selected for execution. However, an executing program gets exclusive access to the
central processing unit A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuit 200px, A circuit built on a printed circuit board (PCB). An electronic circuit is composed of individual electroni ...

central processing unit
only for a Preemption (computing)#time slice, time slice. To provide each user with the illusion of exclusive access, the kernel Preemption (computing), preempts the process control block to execute another one. The goal for Systems programming, system developers is to minimize Latency (engineering), latency. * The kernel program should perform memory management. :* When the kernel initially loads an executable into memory, it divides the address space logically into Region-based memory management, regions. The kernel maintains a master-region table and many per-process-region (pregion) tables — one for each running process. These tables constitute the virtual address space. The master-region table is used to determine where its contents are located in Computer_data_storage#Primary_storage, physical memory. The pregion tables allow each process to have its own program (text) pregion, data pregion, and stack pregion. The program pregion stores machine instructions. Since the machine instructions won't change, the program pregion may be shared by many processes (instances) of the same executable. The kernel is responsible for translating virtual addresses into physical addresses. The kernel may request data from the memory controller and, instead, receive a page fault. If so, the kernel accesses the memory management unit to populate the physical data region and translate the address. :* To save time and memory, the kernel may load only blocks of execution instructions from the disk drive, not the entire execution file completely. :* The kernel allocates memory from the ''heap'' upon request by a process. When the process is finished with the memory, the process may request for it to be freed. If the process exits without requesting all allocated memory to be freed, then the kernel performs Garbage collection (computer science), garbage collection to free the memory. :* The kernel also insures that a process only accesses its own memory, and not that of the kernel or other processes. * The kernel program should perform File system, file system management. The kernel has instructions to create, retrieve, update, and delete files. * The kernel program should perform Peripheral, device management. The kernel provides programs to standardize and simplify the interface to the mouse, keyboard, disk drives, printers, and other devices. Moreover, the kernel should arbitrate access to a device if two processes requests it at the same time. * The kernel program should perform network management. The kernel transmits and receives Network packet, packets on behalf of processes. One key service is to find an efficient Routing table, route to the target system. * The kernel program should provide system calls, system level functions for programmers to use. ** Programmers access files through a relatively simple interface that in turn executes a relatively complicated low-level I/O interface. The low-level interface includes file creation, File descriptor, file descriptors, file seeking, physical reading, and physical writing. ** Programmers create processes through a relatively simple interface that in turn executes a relatively complicated low-level interface. ** Programmers perform date/time arithmetic through a relatively simple interface that in turn executes a relatively complicated low-level time interface. * The kernel program should provide a Inter-process communication, communication channel between executing processes. For a large software system, it may be desirable to Software engineering, engineer the system into smaller processes. Processes may communicate with one another by sending and receiving Signal (IPC), signals. Originally, operating systems were programmed in assembly language, assembly; however, modern operating systems are typically written in higher level languages like C (programming language), C, C++, Objective-C, and Swift (programming language), Swift.


Utility program

A Utility software, utility program is designed to aid system administration and software execution. Operating systems execute hardware utility programs to check the status of disk drives, memory, speakers, and printers. A utility program may optimize the placement of a file on a crowded disk. System utility programs monitor hardware and network performance. When a metric is outside an acceptable range, a trigger alert is generated. Utility programs include compression programs so data files are stored on less disk space. Compressed programs also save time when data files are transmitted over the network. Utility programs can sort and merge data sets. Utility programs detect Computer virus, computer viruses.


Boot program

A stored-program computer requires an initial ''boot program'' stored in its read-only memory to booting, boot. It is to identify and initialize all aspects of the system, from processor registers to device driver, device controllers to volatile memory, memory contents. Following the initialization process, the boot program loads the
operating system An operating system (OS) is system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android (operating system), Android and Mi ...

operating system
and sets the program counter to begin normal operations.


Embedded program

Independent of the host computer, a Peripheral, hardware device might have embedded firmware to control its operation. Firmware is used when the computer program is rarely or never expected to change, or when it must not be lost when the power is off. On a larger scale, an embedded microcontroller is used to control part of a larger system. Examples include aircraft components and life support systems. Applications running on these systems are large and complex. Moreover, they run in Real-time computing, real-time and must be Robustness (computer science), robust. The United States Department of Defense contracted with Groupe Bull, CII Honeywell Bull to develop Ada (programming language), Ada (1983) as a real-time programming language. Central to real-time systems is a Daemon (computing), task facility to permit Parallel computing, parallel processing. Also important are Interrupt, interrupt controls.


Microcode program

A Microcode, microcode program is the bottom-level interpreter that controls the Datapath, data path of software driven computers. (Advances in hardware have migrated these operations to hardware execution circuits.) Microcode instructions allow the programmer to more easily implement the Logic level, digital logic level—the computer's real hardware. The digital logic level is the boundary between computer science and computer engineering. A Field-effect transistor#Gate, gate is a tiny transistor that can return one of two signals: on or off. * Having one transistor forms the Inverter (logic gate), NOT gate. * Connecting two transistors in series forms the NAND gate. * Connecting two transistors in parallel forms the NOR gate. * Connecting a NOT gate to a NAND gate forms the AND gate. * Connecting a NOT gate to a NOR gate forms the OR gate. These five gates form the building blocks of Boolean algebra, binary algebra—the digital logic functions of the computer. Microcode instructions are Assembly language#Mnemonics, mnemonics programmers may use to execute digital logic functions instead of forming them in binary algebra. They are stored in a central processing unit, central processing unit's (CPU) Control store, control store. These hardware-level instructions move data throughout the Datapath, data path. Microcode instructions move data between a CPU's Processor register, registers and throughout the Motherboard, motherboard. The micro-instruction cycle begins when the microsequencer uses its microprogram counter to ''fetch'' the next Machine code, machine instruction from random access memory. The next step is to ''decode'' the machine instruction by selecting the proper output line to the hardware module. The final step is to ''execute'' the instruction using the hardware module's set of gates. Instructions to perform arithmetic are passed through an arithmetic logic unit (ALU). The ALU has circuits to perform elementary operations to add, shift, and compare integers. By combining and looping the elementary operations through the ALU, the CPU performs its complex arithmetic. Microcode instructions move data between the CPU and the Memory controller, memory controller. Memory controller microcode instructions manipulate two Processor register, registers. The Memory address register, memory address register is used to access each memory cell's address. The Memory buffer register, memory data register is used to set and read each cell's contents. Microcode instructions move data between the CPU and the many Bus (computing), computer buses. The Disk controller, disk controller bus writes to and reads from Hard disk drive, hard disk drives. Data is also moved between the CPU and other functional units via the PCI Express, peripheral component interconnect express bus.


See also

* * * * * * * * *


References


Further reading

* * * {{DEFAULTSORT:Computer Program Computer programming Software