1.4 Principles of Programming

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/38

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

39 Terms

1
New cards

Backus-Naur Form (BNF)

is used to describe unambiguously syntax or grammar of a programming language

2
New cards

BNF number structire

Structure: <number> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0

3
New cards

BNF letter structure

Structure: <letter> ::= a | b | c ... x | y | z

4
New cards

BNF mutiples

Structure: <letters> ::= <letter> | <letters><letter>

5
New cards

Syntax Diagrams

They are used in a similar way to BNF but are a more visual representation.

<p>They are used in a similar way to BNF but are a more visual representation.</p>
6
New cards

High Level Languages

These are closer to English, use recognizable words

7
New cards

Low Level Languages

These are closer to internal workings of a computer, e.g. binary or short codes

8
New cards

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

9
New cards

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

10
New cards

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.

11
New cards

Types of Programming Languages

• Procedural
• Non-Procedural
• Object Oriented
• Event driven
• Visual
• Mark-up

12
New cards

Procedural Languages

i) They are used in traditional programming based on algorithms or a logical step-by-step process for solving algorithms
ii) They obeyed ordered instructions
iii) A procedural programming language provides the programmer a way to define precisely each step when performing a task
iv) Allows tight control over the underlying operation of the hardware
v) Used in (large complicated) programs where simlar operations may be carried out at varying stages of the program execution

13
New cards

Non-Procedural Language

i) They allow programmers to specify the results they want without specifying how to solve the problem.
ii) They are to do with rules / making queries / facts.
iii) They are used in database interrogation, where retrieving answers is more important than the exact steps required to calculate the result.
iv) Artificial intelligence, grammar checking, and language translation applications are often written in a non-procedural language.

14
New cards

Object Oriented Language / Programming (OOL/OOP)

i) Uses objects - include both data and associated processing
ii) Enables production of buttons/icons
iii) Uses features such as inheritance, encapsulation, etc

15
New cards

Advantanges of OOP

i) Improved productivity when devloping software due to the flexible and extendable nature of OOP
ii) Software is easier to maintain as OOP is modular and reusable.
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

16
New cards

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

17
New cards

Class (OOP)

It is a template or blueprint for a specific object. It defines an object's instance variables (attributes/properties) and behaviour (methods)

18
New cards

Object (OOP)

An instance of a class that when initiated it allocates memory for the defined attributes and methods of that class.

19
New cards

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).

20
New cards

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

21
New cards

Superclass (OOP)

Is used as the basis for inheritance.

22
New cards

Subclass (OOP)

It is a class that inherits from a superclass.

23
New cards

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

24
New cards

Encapsulation (OOP)

It's the process of hiding implementation of a class and controlling access to its methods and attributes

25
New cards

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.

26
New cards

Object Hierarchy (OOP)

It references descendants of objects acting as properties of an object

27
New cards

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)

28
New cards

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.

29
New cards

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

30
New cards

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.

31
New cards

Standardisation

Agreed standards in programming languages across different manufacturers

32
New cards

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.

33
New cards

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.

34
New cards

BIDMAS

Mathematical order of operations: brackets, indices, division/multiplication, addition/subtraction

35
New cards

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.

36
New cards

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.

37
New cards

Benefits of inheritance?

  • Simple and easy to reuse code

  • Efficient as unecessary repetition

  • Good as it eliminated code duplication

38
New cards

Benefits of encapsulation?

  • Protects objects from unwanted access

  • Reduces human errors

  • Simplifies maintenance

  • Makes the application easier to understand

  • Enhances security of data.

39
New cards

Benefits 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.