2- Programming Flashcards
To yeet and skeet
Variable
A named space in memory, large enough to store a single piece of data. Each variable has a data type.
Constant
A named space in memory with a value that can never change while the program is running. Useful for pi(which will never change) or VAT (which seldom changes). The Python language does not allow for constants, but some other languages do
Boolean
Can be either true or false
Character
A single letter, number, punctuation mark, space, etc.
Integer
Whole numbers - positive, negative or zero
Real
Decimal numbers - positive or negative (zero can also be stored in a ‘real’ variable
String
A collection of characters, used to store names, addresses, phone numbers, etc.
Declaration
Code that causes a variable to exist. Once a variable has been declared, it can be used. Trying to use a variable before it has been declared will cause an error
Assignment
The process of putting a value into a variable. Most languages use a single equals ‘=’ to do this. In the instruction i = 5, the value ‘5’ has been assigned to the variable ‘i’
Sequence
Means that instructions will always execute in the order in which they were written. Every line will be executed once and only once
Iteration
Means ‘looping’. Code that is iterative might be executed multiple times, even though it is only written once
Nesting
This involves placing one programming structure inside another one. The code above contains an IF structure (on the penultimate line) that is nested within the WHILE structure. There is no limit to the number of levels of nesting; that IF structure could have contained another WHILE structure, which itself contained another WHILE structure
Operation
An operation is an action that is performed on one or more pieces of data in order to produce additional data. There are arithmetic operations, relational operations and Boolean operations
Arithmetic operations
A process performed on one or more numbers. Examples include: + - * /
Relational operation
A comparison between two values to check, for example, whether they are equal or whether one is less than or greater than the other. Relational operations are found in IF statements and as part of loops (><=)
Logic operation
A logic operation can have one of only two outcomes - true or false. A logic operator connects together logic expressions to produce more complex logic expressions. AND, NOT and OR are the most commonly used logic operators
Data Structure
A structured (organised) means of storing related data. While a variable can only store a single piece of data, a data structure can contain many
One dimensional array
A data structure for storing multiple data items of the same data type. Think of a one-dimensional array as a row of variables. Instead of each one having a name, the whole array has a single name, while each element in the array has an index number.
The first element is always numbered ‘0’
Two-dimensional array
A data structure for storing multiple data items of the same data type. Like a one-D array but can be considered as a grid rather than a row
Elements are referred to with two numbers, much like ‘x’ and ‘y’ coordinates
Record
A data structure that can accept multiple data items. that do not need to be of the same data type. As far as Python is concerned, there is no difference between array and records, so they are managed in the same way. One record might store a student’s name, year group and average test score
Input
The process of introducing data into a computer system. An example of an input device is a keyboard
Output
The process of communicating data beyond the system, typically to a human user. An example of an output device is a monitor
File
A store of data, used by a program, that continues to exist when the program, and even the computer itself, is no longer running. Many file formats exist, and the practical aspects of this chapter deal with text (.txt) files, typically associated with a program called ‘Notepad’
Casting
Converting a piece of data to a specific data type. E.g: a user might enter a string, and the program might convert it to an integer in order to allow certain calculations
Random
A random number has been selected from a range of numbers if every number in that range had an equal chance of being selected
Subroutine
A small subsection of the whole program that performs a specific, well-defined task. If a library program were to be broken into subroutines, one subroutine might issue a book, one might handle returning a book, one might add a new member, etc.
Benefits of a subroutine
- Each subroutine can be given to a different programmer, so working as a team is straightforward
- Subroutines can each be separately tested, without waiting for the whole program to be finished
- Subroutines that are commonly used, such as to sort a data set, can be reused in other programs, saving time and reducing errors
Parameter
A piece of data that is passed into a subroutine in order for that subroutine to do its job. Multiple parameters can be managed using commas, e.g: def displayTotals(total1, total2, total3)
Calling
A process where an instruction in one part of the code tells another named part of the code to run. If you have a subroutine called ‘promptUser’, the code within that subroutine will never run without that subroutine being called
Python subroutine calling
In Python you have to call a subroutine after the code for that subroutine has been added. If the code on line 18 appeared before the code on line 1, the program would not run
Return
A command in which a subroutine passes a piece of data back to the line of code from which it was called. This is effectively parameter passing, but in reverse. A function is a subroutine that returns a value; a procedure is a subroutine that does not
Difference between a function and a procedure
- A function is a subroutine that returns a value
- A procedure is a subroutine that does NOT return a value
Modularisation
The process of breaking a program into smaller parts called modules. A subroutine is a type of module, and the advantage of dividing a program into either subroutines or modules are the same
Scope
Refers to the visibility of a variable, and can either be local or global
Local variables
Local variables, along with parameters and return values, are usually a better choice than global variables. Another programmer working on another subroutine could modify global variables and make them behave unpredictably. This is not true for local variables
A robust program
A robust program continues to function even when confronted with unexpected events, such as a lost network connection or a user inputting data of the wrong data type
A secure program
A secure program prevents users from accessing or altering data that they should not access or alter. Usernames and passwords make up one approach for keeping a program secure
Validation
Ensuring that data entered into the computer is reasonable and sensible. E.g: checking that a person’s DOB isn’t in the future. Validation does not ensure that the data is correct/true
Range check
Ensures data is within a specified range e.g: ensuring race times for 100m are between 0 and 30 seconds, or ensuring a person’s birthday is not after today’s date
Type check
Ensures that the correct data type has been entered (e.g. integer or Boolean)
Length check
Ensures that a string contains a valid number of characters, such as in a postcode or a phone number
Lookup check
Checks that what the user has entered exists on a list, such as a list of postcodes or days of the week. For shorter lists, the user can select the item from a list themselves (such as a dropdown)
Presence check
Simply checks that the user has entered something. This is essentially a length check that ensures that the length is greater than zero
Authentication
The software process of ensuring that the person accessing a system is the person who is supposed to access that system
Possible methods of authentication
- Usernames and passwords
- Memorable info - prompting for something only the real user should know, e.g: a fav place or name of 1st pet
- Checking that the user is using their usual computer, by logging the IP address
Test Data: Normal (typical)
Data that is valid and that represents how the program would be used
Test Data: Boundary (extreme)
Data that is just barely valid, to check that the extreme ranges of normal input work correctly. It’s also good practise to test just outside the acceptable range
Test Data: Erroneous
Data that should not be accepted by the system. This is included to test whether a program’s validation and error messages work correctly
What is high level language (HLL)
High-level languages are more understandable to humans than low-level languages, so high-level languages are far more popular
Examples of HLL
- Java
- VB
- Python
- C#
What do you need in order to run code written in a HLL
Either an interpreter or a compiler to enable the code that is typed to be translated into machine code so that the computer can run it
What does code in a HLL look like
One line of code might do several things, e.g.:
A = B + C
This instruction finds out the values of B and C, adds them together, then stores the result in B.As one line of code can do several things, one line of a high-level language often translates into several lines of machine code
HLL Suitability
- More appropriate if the program is to be used on a variety of different computer builds
- Far more people are proficient in high-level than low-level languages, and this may dictate the language type used
What is low level language (LLL)
More difficult to understand but can often be executed very quickly by computers
Examples of LLL
- Machine code (which consists of ‘1’s and ‘0’)
- Assembly code, which is a way of making machine code slightly more readable by using mnemonics. For instance, the command 0110 1010 makes no sense, whereas a command like ADD 34, 32 gives a slightly better clue as to what is going on
What do you need in order to run code written in a LL
Machine code does not need to be translated -it is machine ready. Assembly language requires an assembler
What does LLL code look like
One line of code performs a single task. In assembly language:
LDA B
ADD C
STA A
These instructions would perform the same task as ‘A = B+ C’. Machine code, to most people, would be a sequence of unintelligible ‘1’s and ‘0’s, but each line of assembly code translates to one line of machine code.
LLL suitability
- Likely to be used within embedded systems, where specific memory locations and processor functions can be addressed directly
- Suited to time-critical applications, where execution must take place as quickly as possible
Machine code
Machine code is machine-specific, meaning a machine code program written for one computer will not necessarily work on another. This is because different computers sometimes have different internal layouts and components, which can affect the way that machine code is run
Translator
A program that translates source code (which is written by the programmer) into machine code (which can be executed by the comp)
Types of translator
- Assemblers: Translate assembly language
- Interpreters: Translate then execute high level code, one line at a time
- Compilers: Translate an entire high level program before executing it
Computers can only execute machine code. If a program is written using any other language, it must be translated to machine code before it can be executed
An interpreter
Adv:
- A program that contains errors can still be run, up to where the error exists
- Debugging is easier as the problematic line can be more easily pinpointed
Dis:
- Every time you run the program, it needs to be interpreted, which is time consuming
- It is easier for unauthorised people to access your source code
A compiler
Adv:
- A compiled object code file will run more quickly then re-interpreting a source code file
- It is more difficult for unauthorised people to modify a compiled object code file
Dis:
- More memory is needed for the compilation process than for interpretation
- The entire program needs to be error free in order for it to compile