Logic and Languages 2 Flashcards
What is defensive design?
An approach to software development that aims to produce robust and reliable programs.
What is the purpose of authentication?
To ensure a person is who they claim to be
What are some examples of anticipating misuse?
- Malicious inputs
- Attempts to remotely connect
- Attempts to alter access rights
- Brute Force Attacks
What are brute-force-attacks?
Software programs which will try out every combination of letters, numbers and special character
What is data validation?
Checks data meets a set of criteria before you process it and can ensure that data entered is of the right type.
What are the types of validation checks?
Range check Type check Length check Presence check Format check
What is the difference between validation and verification?
Validation can only check that the data entered is reasonable
Verification is used to double-check that the data has been typed in correctly
What is double-entry verification?
Entering data twice
Range check
A number or date is within a sensible/allowed range
Type check
Data is of the right type, such as integer, letter or text
Length check
Text entered is not too long or too short – for example, a password is between 8 and 15 characters
Presence check
Checks that data has been entered, i.e. the field has not been left blank
Format check
Checks that the format of, for example, a postcode or email address is correct
How can programs be written in a way that makes them easily maintainable?
Indentation
Commenting
Use of sub programs
Appropriate naming conventions
Why are sub programs used?
To create code that can be reused multiple times in the program or by other programs, and allows bugs to easily be fixed
What are appropriate naming conventions?
It involves good use of variable and sub program names to make the program easier to read and understand
Why is indentation used?
Indentation makes it easier to see which lines of code are part of different structures (show nesting) - easier to read
Why is commenting used?
Commenting helps programmers understand what a program does and how it does it
What are the types of errors?
syntax error
logic error
What is a syntax error?
A syntax error is one where the programming code written doesn’t conform to the rules of the language
Why does a syntax error appear?
The compiler doesn’t know how to translate the program into machine code so will give the programmer a syntax error. The program cannot be run until all syntax errors are fixed
What is a logic error?
Logic errors appear when the program’s execution appears to run as normal, but not as the programmer intended
What are the types of testing?
iterative testing
final/terminal testing
What is iterative testing?
Iterative testing tests modules and parts of a program as the program is developed
What is final testing?
Final testing tests the whole program at the end of production
What does a test plan test for?
Normal data
Boundary data
Invalid/Erroneous data
What is normal data?
Normal data is test data that is typical (expected) and should be accepted by the system. A number between 0-100, e.g. 5
What is boundary data?
Boundary data is test data at the upper or lower limits of expectations that should be accepted by the system. A number between 0-100, e.g. 0 and 100.
What is erroneous data?
Erroneous data is test data that falls outside of what is acceptable and should be rejected by the system. A number between 0-100, e.g. “ade”
What is a trace table?
This is where the programmer goes through the code, line by line, updating the values of variables and outputs
What is a trace table useful for?
Determining the purpose of an algorithm
Finding the output of an algorithm
Finding errors in an algorithm
How is a trace table used to help find errors in a program?
Variable names and outputs are put in columns. The programmer traces through the program line by line updating the values of variables and outputs. A row is used for each iteration.
How are logic errors found?
using a trace table
using the print statement
What is the purpose of testing?
To find errors and determine (then patch) vulnerabilities so the program functions as intended
What is a truth table?
A truth table is a method of representing every possible output based on the inputs to a Boolean expression.
What is NOT also known as?
negation
What is OR also know as?
disjunction
What does an AND operator do?
Only returns true if both conditions are true, else it returns false.
What does the OR operator do?
The operator returns true if either of the conditions are true. It only returns false if both conditions are false
What does the NOT operator do?
Takes one input and reverses it
What do Boolean operators do?
Take Boolean inputs and evaluate to a Boolean value
How do you find out the number of rows on your truth table?
Do 2 (base) to the power of n (the number of inputs) E.g. 2^3 = 8 rows
What is machine code?
Is written in binary and is the language all code is translated to as it is in a format the CPU can process
What are some examples of low level language?
Machine code
Assembly language
What is assembly language made up off?
simple mnemonics (or text)
Why is assembly language a low level language?
As each instruction corresponds directly to a machine code instruction (have an almost one-to-one relationship with machine code)
What are the disadvantages of assembly language?
It is processor-specific
It has to be translated into machine code before it can be executed
It requires more lines of code
What are the advantages of low level languages?
It can be executed faster
Code requires less RAM
Statements in LLL can be used to control and manipulate hardware
What are the advantages of high level languages?
Easier to learn
Programs can be written faster in a high-level language
It is easier to understand and debug a high-level language
Uses fewer lines of code
Not hardware-specific (portable) - therefore can be executed on many computers with the correct translator
What are high level languages?
They are programming languages that are similar to the human language
What is a compiler?
Scans through the whole code and translates the instructions in a HLL into machine code. It produces object code that cannot be edited or adapted.
What is the code produced by a programmer called?
Source Code
Where can object code be saved in?
A storage drive (in either a library file, executable file or object file) and run whenever required
What is an interpreter?
It translates instructions in a HLL into machine code. It works line-by-line, it translates a line and then immediately executes it.
What are the advantages of an interpreter?
If it reaches a line with a syntax error, it stops and displays an error message
It translates each line of code and executes it immediately
What are the disadvantages of an interpreter?
Takes more time to execute as each instruction is translated before it is executed
The interpreter must be installed to run the program
Source code can be edited or adapted
What are the advantages of a compiler?
A compiled program executes faster as it is already in machine code
Once compiled, the compiler and source code is no longer required
Once compiled, source code cannot be edited or adapted
What are the disadvantages of a compiler?
It scans through the whole code and then displays a list of errors
What are examples of a High-level language?
Ruby C# C++ Java Python
What are the types of translators?
Assembler
Compiler
Interpreter
What is bytecode?
Bytecode is source code that has been compiled into low-level code and can be interpreted on many different types of processors using an interpreter. It is an intermediate stage between high-level and low-level language.
What is an IDE?
It is an Integrated Development Environment. An application that provides a selection of tools for programmers, allowing them to code using additional tools all in one place
What are some examples of IDEs?
Visual Studio (C#)
Eclipse (Java)
IDLE (Python)
What are some features of an IDE?
Line Numbers Syntax Highlighting Error Diagnostics Runtime Environments Code Folding Debugging Tools Translator
What do line numbers do?
Line numbers allow a programmer to clearly see each new line of code
When errors are found, the line number that they occur on will also be stated
What does syntax highlighting do?
Syntax highlighting is where the colour of the text changes to show different parts of the program.
Errors are also highlighted/underlined within the code.
What do error diagnostics do?
Error diagnostics help a programmer to find where they have made a mistake
What does debugging code involve?
The use of breakpoints - which are set by the programmer so that the IDE stops the program mid-way through running
They allow the programmer to step through code line by line and watch variables as they change
What does a run-time environment do?
The run-time environment allows a programmer to test their program while it is running. It goes useful information to the programmer if the program was to crash.
Why are editors used?
They are used to write and edit programming code
What is a translator?
A program that converts code from one language into equivalent code written in another - as all code needs to be translated to machine code in order to run
What is a test plan?
A test plan is a list of requirements designed to ensure that the code functions as intended.