Principles Of Programming Flashcards
Define programming paradigms
A programming paradigm is the fundamental structure and approach of a programming language
Name all of the different programming paradigms
Procedural languages
Non procedural languages (iterative)
Event driven programming
Visual programming
Mark-up languages
Object-oriented programming
They aren’t mutually exclusive (multiple can be used for different languages)
Procedural languages
An ordered set of instructions in a sequence that the computer follows strictly
Logical step by step process
Allows programmer to define precisely each step when performing a task
Allows the programmer to control the steps being carried out by the processor
Could be used for writing a wide range of programs e.g. business applications, stock control, pay roll
Not ideal for GUI based systems which arent best expressed in a linear algorithm
Non-procedural languages
Allows programmers to specify the results they want without specifying how to solve the problem
Written as a list of facts and rules
Order of the facts and rules is unimportant
The computer can process can process these facts and rules so as to find the solution to a problem
Used to make e.g. AI systems like expert systems
Sometimes used in database interrogation where returning answers are more important than the exact steps required to calculate the result
Traditional/classic procedural languages
Text based
Program starts running ‘main procedure’ and calls other procedures from there
No problem if developing simple text-based UI
More difficult if designing GUI
Event-driven programming
Could be text based but usually apart of a visual programming language
Subroutines are written that react to events that occur
E.g. mouse click
Visual programming languages
Reduced need to traditional programming
Easy creation of GUI objects e.g. forms, buttons, lists etc.
Rapid development of professional looking applications
Languages e.g. visual basic allow GUI to be developed rapidly
Programming is event driven
Mark-up languages
Such as HTML and XML are not really programming paradigms but are a key part of Web programming
Mark up languages add commands to a text document to add further meaning to the text or to the structure
How is bnf written
BNF consists of a list of statements defining ‘meta variables’ written between angle brackets <>. The | symbol is used to represent OR. The := or ::= symbols are used to mean “is defined as”.
E.g.:
:= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Do questions on it
How are syntax diagrams written
Syntax diagrams are an alternative method of describing the syntax of a language. A path is traced from left to right
What does object oriented programming entale
Uses: identifiers, selection (ifs), iteration(loops), classes, objects, methods and attributes (attribute is also called a property)
What is an object in object oriented programming and what 2 things does it consist of?
Objects can be created for ‘things’ that the program needs to manage.
E.g. student, stock, alien (in a game)
Consists of two things:
Data fields (attributes) about the object, such as stockID, Description, etc.
Subroutines/Procedures (methods) that can be performed on the object, e.g. AddStock, DisplayQuantitySold, etc.
What is encapsulation
Collecting all the attributes and methods related to one thing together into a single object rather than having them spread throughout a program
The definition of an object is a class
What are protected attributes
Can only be used by derived classes( or sub-classes) that inhdrit from the class
What are private attributes
Are accessible only within the class
What is inheritance in object oriented programming
Classes can be reused in future programs and objects can be created that inherit attributes and methods from another object
What is the parent class also known as
The superclass
What is the derived class sometimes known as
Subclass
What are the symbols which represent inheritance in UML diagrams and which ones which
(#)denotes a protected attribute or method
(-) denotes a private attribute or method
(+) denotes a public attribute or method
What are the advantages of object oriented programming
The ability to combine data and the procedures that use the data together in one object is a much more intuitive way of thinking about a problem
Makes the program easier to maintain and understand as the object complexity can be hidden from the program / people who use it: encapsulation
Inheritance- easy to reuse objects in other programs and if necessary create new objects that inherit from other objects without having to recode
Natural languages vs computer languages
Natural languages are ambiguous I.e. there can be more than one meaning to sentences
Computer languages are designed to be unambiguous the syntax rules of the language
Low level languages
E.g. assembly language
Has to write software in a computer-centric way, interacting directly with registers, memory locations, etc.
One low level instruction translates into one machine code instruction
Usually translates into less instructions so will run faster. Smaller programs.
Slower and more difficult to program
Uses more cryptic and harder to understand references to memory locations and sections of code
Time to convert is negligible so runs immediately
High level languages
E.g. java, python etc.
More human-centric, not requiring direct access to (or knowledge of) the internal registers of the processor.
One line of code translates to many machine code instructions
Compiler will generally not translate into as few machine code instructions
Easier to program
Identifiers can be self documenting
Requires compilation before code can be run for the first time
Easier to create modules that can be reused and accessed by other parts of the program
Allows use of powerful commands that can perform quite complex tasks
Where will low level languages be used
Embedded processors in e.g. washing machines as is small and efficient
Why is bnf preferable to ordinary English
English is ambiguous whereas bnf is unambiguous
What is the purpose of bnf
To describe unambiguously the syntax /grammar/ rules of programming / computer language
Problems that might be encountered when using a recursive algorithm
Could run out of memory (stack space)
Difficult to debug (dry run) if producing incorrect results as it is difficult determining which recursive call produced the error
Define rounding
The result is given to the nearest value
Define truncation
Approximation of a numeric data item by ignoring all information beyond a given number of significant figures
Why do programmers find syntax diagrams and bnf notation preferable methods for describing the syntax of programming languages compared to natural English
-english language rules can be ambiguous which is a problem
-syntax diagrams provide diagram representations which are easy to follow
-BNF definitions can easily be encoded when writing a compiler