2 programming
what does an interpreter do?
- an interpreter reads the source code one instruction or line at a time, translates this line and executes it. - the next line is then read and translated and so on. - this has to be done every time the program is run.
what are the advantages of low-level languages
- assembly language is often used in embedded systems - gives the programmer complete control over system hardware components - can directly control the CPU, memory and registers - very efficient code can be written for a particular type of processor so that it will need less memory and run faster than a program written in a high level language - it's understood by the computer, so doesn't need translating like assembly language or high level programs do and will run faster as a result
advantages of high level
- built in functions in high level languages which don't need to be written by the programmer - commands are written using normal text such as print input etc. - this makes writing programs easier to work with - fewer lines of code are needed to carry out the same tasks as one command translates into many machine code commands - so this means writing the necessary code would take less time - programs written in high language are easier to read and debug, so this makes finding any errors easier - not machine specific
what is machine code?
- directly executable by the processor - the language that "computers understand" - uses binary - all programs must be translated into machine code
disadvantages of interpreters
- every line has to be translated every time the program is executed making it slower - all users of the program must have the interpreter installed as well as the source code
explain the main differences between low-level and high-level languages
- high level languages are much easier to use than a low level language such as machine code, or assembly language. the advantage of a low level language is that it runs very fast on the computer. - high level understandable by humans
disadvantages of compilers
- if any errors are found during compiling it carries on compiling the rest of the program and reports all errors - you cannot make changes to the program without going back to the original source code, editing and the recompiling
disadvantages of low level programming languages
- machine specific so will only work on the computer the program was written on - as one assembly language command translates into one machine code command, the number of lines of code will be a lot more than a program written in a high level language - more difficult than high level languages to write programs with, read and find errors - programs need to be translated using an assembler whereas machine code does not which could make the program run slower than a machine code program
disadvantages of high-level languages
- programs need to be translated using a compiler or interpreter whereas machine code does not which could make the program run slower - high level languages don't give you access to the hardware like low level languages do so you do not get the same level of control and memory management may be less efficient.
what does a compiler do?
- the code written by the programmer is called the source code. the machine code produced by a compiler is called the object code. - a compiler reads all of the source code and if there are no errors translates it into a complete machine code program which is output as a new file that can be saved and run. - a program only needs to be compiled once.
advantages of compilers
- the translation is done only once and as a separate process - the program is already translated into machine code and will run faster than an interpreted program - it protects the software from competitors as they cannot see the source code
what is assembly code?
- uses mnemonics - easier to program in than machine code but still difficult. - one assembly language instruction translates to one machine code instruction (1-1 relationship)
advantages of interpreters
- when an error is found the interpreter reports it and stops so the programmer knows where the error occurred - the program can be easily edited as it always exists as source code
what is a string data type?
can contain any character you can type on a keyboard
what is a data type?
a classification of data which tells the compiler or interpreter how the programmer intends to use the data
what's the difference between a constant and a variable?
a constant is a variable which doesn't change throughout the program
what is a definite loop?
a loop that repeats a set amount of times e.g. FOR
what is an indefinite loop?
a loop that repeats until a condition is met e.g. while
what is a subroutine?
a sequence of program instructions that perform a specific task, and is used to break down a larger program
what is an array?
a series of memory locations which holds a series of items of data. All data in an array must be the same data type
what is a data structure?
a specialised format for organising and storing data
what is a local variable?
a variable that is declared within a function and cannot be accessed by statements that are outside of the function
what is a parameter?
a variable that is passed into a subroutine
what is an integer?
a whole number (not a fraction) that can be positive, negative, or zero
what is constant declaration?
declaring a constant as opposed to a variable (a constant is a variable which can't be changed)
what is real division?
division where answer can be a decimal number
what is a boolean data type?
either true or false
what does the NOT boolean operation do?
expression must be False in order for the condition to be True
when should you use iteration?
if you see repeated patterns in code / repeated lines or blocks of code
what is selection?
in a selection structure, a question is asked, and depending on the answer, the program runs a specific block of code
what is concatenation?
joins two strings together
what is a variable?
locations (slots) in memory where data is stored and can be accessed and changed as the program runs
what is a real data type?
numerical data which contains decimal numbers (float in python)
what does the OR boolean operation do?
only needs one part to be True for the condition to be true
what is a substring string operator?
returns a slice of the string with a number of characters from the string
what does the DIV function do?
returns the divisor and no remainder or decimal
what does the MOD function do?
returns the remainder
what is nested selection?
selection within another selection
what is assignment?
sets or resets the value stored in the storage location denoted by a variable name
what is a list?
similar to an array but can have different data types
what is a character data type?
single letter or character
what is the difference between functions and procedures?
structurally the same, however a function returns a value
what is an argument?
the actual values when the subroutine is called
what does an assembler do?
translates a low-level language program into machine code
what is iteration?
when a block of code is repeated a specific number of times, or until a condition is met
what is a while loop?
when a condition is evaluated at the beginning so will finish the programming until the end of the loop
what is a repeat-until loop?
when a condition is evaluated at the end of a loop so the code is executed at least once. the program then loops back and the condition is evaluated again.
what is variable declaration?
when you declare a variable to specify its name and characteristics /content
what does the AND boolean operation do?
all parts of a condition must be True for the condition to be True
what is nested iteration?
an iteration loop within another iteration loop
what are low-level languages?
are used to write programs that relate to the specific architecture and hardware of a particular type of computer.
what are high-level languages?
are written in a form that is close to our human language, enabling to programmer to just focus on the problem being solved. - require translation - portable - easier to read, write and maintain - allow access to module libraries - use data types and data structures, selection statements, and repetition/iteration constructs