1/62
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Backus-Naur Form (BNF)
is used to describe unambiguously syntax or grammar of a programming language
BNF number structire
Structure: <number> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0
| - or
::= - is defined by
<> - non terminal
BNF letter structure
Structure: <letter> ::= a | b | c ... x | y | z
How does BNF use recursion?
Structure: <word> ::= <letter> | <letter> <word>
This uses recursion so we can easily define a structure with infinite letters as you recrusively call the <word> to add more. To have atleast two letters in the word you would start it wih <letter><letter> for a minimum of two
You go to the second recursive option untill you wanty to stop
Whats parsing
Working out if something is valid based on BNF rules
Syntax Diagrams
They are used in a similar way to BNF but are a more visual representation.
It uses circles for terminals (cant be broken down like 1 or A)
It uses a box for non-terminals
It uses an arrow going back for recursion

High Level Languages
These are closer to English, use recognizable words
Low Level Languages
These are closer to internal workings of a computer, e.g. binary or short codes
Why use high-level language?
- Easier to understand, learn, and program as commands are more English-like.
- Identifiers can be long and meaningful
- They allow the use of powerful commands that perform quite complex tasks.
- Allows creation of modules that can be re-used and accessed by other parts of the program
-Abstraction is used to hide details from machine code
What are some high level languages?
Java, Python, Visual basicm, C++, C#
Why use low-level languages?
- Ideal for critical execution speed, e.g. bootstrap loader
- More efficient than high-level language programs
- Require less time for translation into machine code
- Generally result in smaller executable programs
-Closer to machine code and needs a better understanding of computers architecture to use
-Can normally be converted into machine code without a compiler
What are some Low level languages?
Machine code, Assembly
Applications requiring low level languages
i) Device Drivers: Low-level language must be used to directly access memory addressed to full control hardware.
ii) Embedded software: software that runs on simple devices using simple microprocessors, such as washing machines and microwaves, will need direct access to the hardware.
iii) Real-time software: simulators of ly-by-wire systems that require precise processing, timing, or accuracy could potentially benefit from using a low-level language.
iv) Assembly language can be produce more compact code which can be important when placing on a chip.
v) Custom hardware such as robotics need to be manipulated with low-level languages for optimal performance.
What are programming paradigms?
A style of approach to programming that defines how code is structured and executed to solve a problem. The paradigm used depends on the type of problem
Types of Programming Paradigms
• Procedural
• Object Oriented
• Event driven
What are examples of systems that would use each paradigm?
Procedural
System utilites - file managment or command line focusing on sequence of commands
Scientific calculations - Clearly defined and sequential processes for data analysis/mathematical computation
Embeded systems
Event
GUI
Gaming
Object
Large complex systems
Procedural Languages
It uses a sequence of instructions that may be contained in procedures and instructions within those procedures are carried out step-by-step. Commands are entered in desired sequence of execution, which is suitable for simple applications with linear flow.
It emphasises code re-use and modular design allowing creation of procedures and functions for repetitive tasks
One on the most used paradigms because it can be applied to a wide range of problems, and is relatively easy to write.
Where is a procedural approach best suited?
Procedural languaes use traditional data types (strings) and also provide data structures like dictionaries and arrays. It also has other structures such as: sequence, selection, iteration, and recursion.
As a result procedural programs are best used to problems which can easily be set as a series of instructions using the above structures
What are areas of procedural programming?
Predefined functions
Library of functions available.
Saves time.
Local variables
A variable that can only be used in the function that it is declared.
Global variables
Variables are available to all functions and methods within the code.
Parameter passing
Allows passed data to be assigned to variables, equations and commands within a function.
Modularity
The structure of the code is divided into smaller blocks.
Allows for code to be repeatable, making the code more efficient.
Top-down approach
Define the main goal of the program, and then assess the components required to complete it.
The components are then divided into smaller modules.
What is modularity in programming?
Refers to breaking down a program into smaller, self-contained modules with each responsible for a task/function. This improves organisation and makes development, maintenance and understyanding easier - which allows for better collaboration and scalability in development.
What are modules?
A module is a self contained block of code that will have indepentand development which promotes reusability.
A modular program will contain:
-Subroutines
-Classes and objects
-Pre-defined functions
What are visual languages?
Allow developers to drag and drop functions onto a screen.
+ This allows developers to focus on the logic of an applicationg rather than the syntax of the language
- Inappropriate for complex applications due to limiations in space
Scratch is an exmample of this and LabVIEW (an automation program for equipment)
What is event driven programming?
Programming using an event that will lead to a response. These most likely involve a GUI for ease of interaction. It will sit on a loop waiting for user to interact and then the listener will run the process called by the interaction.
The flow of control is dictated by user actions (mouse clicks etc)
What are the steps of event driven programming?
The program sits on a loop
The user will interact with the system using an input device
The listener will recieve the instruction
After the event has been initiated the OS will send the even to the application event queue
Whats an event?
An action that can be reacted to
Whats an event handler/listener
The block of code that is run in response to an specific event
Whats an event loop
A loop that continuously checks for events by running a loop contstantly listening. A queue data structure with list of events that have been raised (an event is added to the queue after detection). This meants events are executed in the order they are called
Whats a trigger function
A function that handles/processes events
What is service oriented porcessing?
Background services that are triggerd by events (like USB recognition) which doesnt require a UI as it is background
What is time driven programming?
Program that is sensetive to time as it checks time and does an instruction (like an alarm clock which exucutes an instruction at a certain time.)
What does a trigger function do?
Match events to event handlers
Object Oriented Language / Programming (OOL/OOP)
Software is designed around objects rather than functions and logic. It encapsulates data and behaviour into reusable objects promoting concepts such as inheritance, encapsualtion, etc.
This is effective for large complex systems as is makes code more organised and easier to maintain
Advantanges of OOP
i) Improved productivity when devloping software due to the flexible and extendable nature of OOP (High resuability due to polymorphism and inheritence)
ii) Software is easier to maintain as OOP is modular and reusable (Classes can be resued and updated easily)
iii) Development is faster due the reusable code and libraries
iv) Development is cheaper
v) Software can be tested more easily, making it more high quality
vi) Software is easier to design as model the real world
OOP - Disadvantages
i) OOP is difficult and not as 'logical' to some developers, it is complex to create application in OOP
ii) Software can become larger - more code than procedural programs
iii) OOP programs can run slower than PP as there is more code to execute.
iv) OOP cannot be used for all types of software application such as machine learning and AI.
v) OOP can be difficult to debug
vi) No suited for programs where few components are reused or smaller problems
vii) Requires advanced plannuing of the solutions - which could improve the software overall in the end
What does each object do?
Stores data (properties)
Performs actions (methods)
Class (OOP)
It is a template or blueprint for a specific object. It defines an object's instance variables (attributes/properties: that are characteristics or data of an object) and behaviour (methods)
Object (OOP)
An instance of a class that when initiated it allocates memory for the defined attributes and methods of that class.
Method (OOP)
A method is a programmed behaviour/subroutine that is included in an object of a class. A method can only access data within its own object (encapsulation).
Inheritance (OOP)
i) Enables new objects to take on the properties of existing
objects
ii) Inheritance defines relationships between classes and organises classes into groups.
iii) Inheritance enables classes that are similar to existing classes to be created by indicating differences (rather than starting again) and thereby allows code to be organised and re-used effectively
Superclass (OOP)
Is used as the basis for inheritance.
Subclass (OOP)
It is a class that inherits from a superclass.
It uses inherited properties/methods, adds new methods/properties, and override inherited methods
Abstraction (OOP)
Process of hiding non-essential features and showing essential features
By:
i Hiding complexity
ii Simplifying the interface
iii Facilitating easier use and understanding

Encapsulation (OOP)
It's the process of hiding implementation of a class and controlling access to its methods and attributes. Creating a class is encapslation
Polymorphism (OOP)
is the characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form.
The same method can be used by different objects but behave differently. (Like makenoise() for different animals would behave differently)
Object Hierarchy (OOP)
It references descendants of objects acting as properties of an object
What is method overloading
multiple methods with the same name but different parameters (run based on inputs)
Whats method overiding?
A subclass provbides its own version of a method that is already defined in the parent calss
Event Driven Language
i) Used in situations relying on events
ii) Event could be triggered by input devices (on mouse click) or external sensors (e.g., pressure)
Event Driven Language concept
program will sit in a loop, waiting for the user to perform an action. When an action occurs, a function will run to process that action.
Visual Language
i) particularly suitable for production of objects / buttons/icons, etc
ii) particularly suitable for developing in a GUI/Windows/graphics content/event driven environment
iii) may be easier to learn / more intuitive because they are visual - there is very good help/tools available
Mark-up Languages
i) Mark-up languages use tags to specify the format of data Eg: HTML-Hypertext Markup Language
ii) The commands in HTML are called tags, are surrounded by chevrons. e.g., <h1>
iii) These can easily be written in any basic text editor.
iv) The tags are interpreted by the browser
when the page is displayed.
v) XML (eXtensible Mark-up Language) is another mark-up language that is commonly used in web applications.
vi) XML is used for structuring and marking-up data for storage rather than information for display.
vii)The developer is free to create their own tags and specify their own meaning to them.
viii)Mark-up languages are commonly combined with other languages, such as JavaScript with HTML.
Standardisation
Agreed standards in programming languages across different manufacturers
Ambiguity in natural language
Ambiguity in natural language means that a statement can be interpretd in more than one way.
This is difficult enough in English, but it makes it impossible for a computer to interpret.
Natural Language VS Computer Language
Natural language can be defined as the spoken and written words humans use to communicate with one another.
In natural language, words can be ambigious; one word can have more than one meaning.
An example of an ambigious word in English is 'break'.
Computer language syntax can be defined as the set of rules that a program statement must follow.
High-level compiter language syntax must be unambigious.
Each program statement must have a specific purpose.
If there was ambiguity in computer language syntax, it would be impossible to translate into machine code.
An example would be the statement 'break'. The break statement must force the program to leave only a construct and nothing else.
BIDMAS
Mathematical order of operations: brackets, indices, division/multiplication, addition/subtraction
What is a constructor?
A class constructor is a type of subroutine called to create an object. It is called automatically when an instance of a class is created and typically initializes the object's attributes.
What is a destructor?
It allows an object to clean up any memory allocated to it. It also released unmanged resources like file handles, and database connections.
Benefits of inheritance?
Simple and easy to reuse code
Efficient as unecessary repetition
Good as it eliminated code duplication
Benefits of encapsulation?
Protects objects from unwanted access
Reduces human errors
Simplifies maintenance
Makes the application easier to understand
Enhances security of data.
Examples of polymorphism?
Inheritance – allows you to create a superclass with properties and methods that are general. This superclass becomes the abstract class, where objects are then only instantiated from the inherited subclasses. A sub class can access all properties and methods from the superclass, but will have its own unique set of properties and methods.
Method overloading – This occurs when multiple methods in the same class share the same name but have different parameter lists (different types, numbers, or both). E.g. a class might have a method called add(int a, int b), and another method add(double a, double b). The appropriate method is chosen at compile time based on the arguments passed.
Method overriding – This is where a sub class overrides a method that exists in the superclass. In this case the sub class will have the same method name, but will execute something different inside that method. The method in the sub class overrides the method in the superclass when it is called via the instantiated object.
Operator overloading – This is where the operator name or symbol can be used for multiple operations. i.e. an operator can be bound to more than one implementation of the operator.
Show how polymorphism is useful?
if(Animal equals Tiger)
{
print roar
}
else if(Animal equals Mouse)
{
print Squeak
}VS
Animal.MakeNoise();
It keeps code more readable by reducing conditions and more reusable
What is a computer program? and how to they achieve this function?
A set of instruction that is designed to interact with the system. They utilise a set of control constructs/structures that are used to manipulate data within a system.
How do computers run code?
It needs to be translated by a translator from source code into machine code that the computer can understand