1.2.4 Types of Programming Language
(a) Need for and characteristics of a variety of programming
paradigms.
Programming Paradigms
• different approaches to using a programming language to solve a problem
• most modern programming languages allow for more than one paradigm
Imperative
• code clearly specifies the actions to be performed
• e.g. procedural, object-oriented
Declarative
• focuses on stating the desired result
• details on how to obtain the result are abstracted from the user
• e.g.
functional: programs are made by reusing a set of functions, lines of code consist
of function calls that are often combined within each other
logic: statements are written to describe the problem to be solved, queries are
used to find answers based on rules of the problem
(b) Procedural languages.
Procedural programming
• uses a sequence of instructions
• traditional data types are built into the language (e.g. integers, strings)
• provides data structures (e.g. dictionaries, arrays)
Structured programming
• a subsection of procedural programming
• four main programming structures define the control flow of a program
Sequence
• code is run line-by-line from the top to the bottom of a program
, Selection
• certain sections of code will run if a specific condition has been met
• e.g. if statements, switch ... case statements
Iteration
• sections of code that will repeatedly be executed a set number of times or while a
condition is met
• e.g. for loops, while loops
Recursion
• when function call themselves
• until a condition (base case) is met which does not call the function
Advantages
• relatively easy to learn and interpret
• executes straightforward tasks efficiently
Disadvantages
• large programs will be difficult to manage
• lack of modularity may lead to code redundancy
(c) Assembly language (including following and writing simple
programs with the Little Man Computer instruction set). See
appendix 5d.
Assembly Language
• low level language
• next level up from machine code
• uses mnemonics which are abbreviations for machine code instructions
• each mnemonic is represented by a numeric code
Mnemonic Instruction Function
ADD add adds the value at the given memory address to the value
in the accumulator
SUB subtract subtracts the value at the given memory address from
the value in the accumulator
STA store stores the value in the accumulator at the given memory
address
(a) Need for and characteristics of a variety of programming
paradigms.
Programming Paradigms
• different approaches to using a programming language to solve a problem
• most modern programming languages allow for more than one paradigm
Imperative
• code clearly specifies the actions to be performed
• e.g. procedural, object-oriented
Declarative
• focuses on stating the desired result
• details on how to obtain the result are abstracted from the user
• e.g.
functional: programs are made by reusing a set of functions, lines of code consist
of function calls that are often combined within each other
logic: statements are written to describe the problem to be solved, queries are
used to find answers based on rules of the problem
(b) Procedural languages.
Procedural programming
• uses a sequence of instructions
• traditional data types are built into the language (e.g. integers, strings)
• provides data structures (e.g. dictionaries, arrays)
Structured programming
• a subsection of procedural programming
• four main programming structures define the control flow of a program
Sequence
• code is run line-by-line from the top to the bottom of a program
, Selection
• certain sections of code will run if a specific condition has been met
• e.g. if statements, switch ... case statements
Iteration
• sections of code that will repeatedly be executed a set number of times or while a
condition is met
• e.g. for loops, while loops
Recursion
• when function call themselves
• until a condition (base case) is met which does not call the function
Advantages
• relatively easy to learn and interpret
• executes straightforward tasks efficiently
Disadvantages
• large programs will be difficult to manage
• lack of modularity may lead to code redundancy
(c) Assembly language (including following and writing simple
programs with the Little Man Computer instruction set). See
appendix 5d.
Assembly Language
• low level language
• next level up from machine code
• uses mnemonics which are abbreviations for machine code instructions
• each mnemonic is represented by a numeric code
Mnemonic Instruction Function
ADD add adds the value at the given memory address to the value
in the accumulator
SUB subtract subtracts the value at the given memory address from
the value in the accumulator
STA store stores the value in the accumulator at the given memory
address