2.5 Programming languages and Integrated Development Environments Flashcards
(21 cards)
What are the two type sof programming languages used within computer systems?
Low-level languages
Examples: machine code, assembly language
High-level languages:
Python, C#, java, visual basic
Why do programmers use high level languages?
High-level languages use code that is similar to a natural human language, such as english, making it easier to understand and use the language.
Using high-level languages lead to fewer errors and allows for more powerful and complex commands compared to low-level languages.
However, a high-level language must be translated into machine code (binary) before it can be run, because high-level languages cannot be processed directly by the CPU.
When are low level languages used, and what are two types?
Low-level languages do not closely resemble a natural human language, making it harder for humans to understand and write in.
Low-level languages are used when a program must be executed quickly or when programmers need to write code that interacts directly with the hardware, such as device drivers.
Two types are machine code and assembly language
Characteristics of machine code
Binary representation of instructions in a format that the CPU can decode ad execute
Have an operation code (opcode) instruction and address or data to be used (operand)
This is pure binary code that the CPU can directly process and execute.
it is extremely tedious and difficult for humans to understand and write machine code.
However, machine code can be used when a programmer needs to perform a very specific command that can’t be done in a high-level language.
Machine code will be executed faster than high-level programs because it is already in a format that the CPU can execute and does not need to be translated.
Advantages and disadvantages of machine code
- executed faster than high-level languages
- no need to be translated
- extremely difficult for humans to understand and write as in binary
- processor specific (same can’t be used on different computers)
Characteristics of assembly language
Assembly language uses specialised command mnemonics to perform actions. See the Assembly Language section in the programming tab for a list of mnemonics such as INP, OUT and HLT.
Assembly language is preferred by many programmers over machine code because it is easier to understand and spot errors.
It is faster to execute than high-level languages and, like machine code, can be used to directly control the CPU.
Assembly language is:
written in assembly language
translated by an assembler into machine code
used for embedded systems and device drivers where instructing the hardware directly is necessary
one instruction translated into one machine code instruction
the code works on one type of processor only
the programmer works with memory directly
code is harder to write and understand
memory efficient
code is fast to execut
advantages and disadvantages of assembly language
- fast to execute
- memory efficient
- can be used to directly control the CPU
- code is harder to write and understand
- code is processor specific
What is a translator and what are the two main types
A translator changes (translates) a program written in one language into another language (usually machine code).
A translator is needed as code that is written in both assembly language and high-level language needs to be converted into binary machine code for execution.
Two types: interpreter and compiler
What is an interpreter?
An interpreter converts high-level language one line at a time into machine code and executes it.
Translates source code from high level languages into machine code ready to be processed by the CPU.
The program is translated line by line as the program is running.
Advantages and disadvantages of an interpreter
Adv
- Easy to write source code because the program will always run, stopping when it finds a syntax error.
- Code does not need to be recompiled when changed, and it is easy to try out commands when the program has paused after finding an error
- this makes interpreted languages very easy for beginner programmers to learn to write code
Disadv
- translation software is needed at run time
- speed of execution is slower
- code is not optimised
- source code is needed
What is a compiler
A compiler converts high-level language into machine code for execution at a later time. The entire program is converted at once.
translates source code from high-level languages into object code and then into machine code ready to be processed by the CPU.
the whole program is translated into machine code before it is run
Advantages and disadvantages of a compiler
Adv
- no need for translation software at run time
- speed of execution is faster
- code is usually optimised (code runs faster or performs better wthout changing what it does_
- original source code is kept secret
Disadv
- source code is easier to write in a high level language, but the program will not run with syntax errors which can make it more difficult to write the code
- code needs to be recompiled when the code is changed
- designed for a specific type of processor
Interpreter vs compiler
interpreter
Execution Method:
An interpreter translates source code (high level code) into machine code one line at a time.
Execution Speed:
An interpreter is slower than a compiler because the code must be reinterpreted each time the program is run.
Complexity:
Interpreters are smaller, simpler programs.
Error Reporting:
In error reporting, the interpreter would encounter the errors and report it to the user immediately and stops the program from running.
Repetition:
Interpreted programs can be edited and run without translating the whole program.
Interpreters must reinterpret the program every time it is run.
Compiler:
Execution Method:
A compiler translates all the source code (high level code) into machine code in one go.
A compiler produces an executable file that will run on other machines without the compiler needing to be installed.
Execution Speed:
Compilers can produce much more efficient code than interpreters making the compiled programs run faster.
Complexity:
Compilers tend to be large complex programs.
Error Reporting:
The compiler would analyse the entire program, taking note of where errors have occurred and record them in an error file.
Repetition:
Compilation requires analysis and the generation of the code only once, whereas interpreters must re-interpret each time.
However, compiled programs have to be re-compiled after any changes have been made.
What are the Common tools and facilities available in an Integrated Development Environment (IDE)
Editor
Compilers and interpreters
break point
variable watch/watch window
trace
error diagnostics and debugger
run time environment
Editor
The editor is software that allows the programmer to enter and edit source code.
Features include:
automatic formatting (indentation)
automatic line numbering (helps identify exactly where error occurred)
automatic colour coding (eg. variable and print commands are different)
statement completeion (auto-complete)
Compilers and interpreters
Both tools convert source code into machine code to be executed by the CPU.
Compiler - converts the entire source code into executable machine code at once. Compiled once, no need to recompile (unless code changed).
Interpreter - converts source code into machine code line by line. Interprets the code each time the program is run.
Break point
The programmer selects a specific line and the program displays the variable values at that point.
The code can then be executed one line at a time to find exactly where the error occurs. This process is called single-stepping.
Variable watch/watch window
Displays the current value of the selected variable.
A variable can be watched lin-by-line to see how the value changes.
Trace
Logs the values of the variables and outputs of the program as the code is executed line by line.
Error diagnostic and debugger
Both tools are used to display information about an error when it occurs, such as the line it has occurred on and the error type (e.g syntax).
These tools may also suggest solutions to help the programmer find and fix the error.
Run time environment
A runtime environment allows a program to run on a computer system. It checks for run time errors and allows users to test the program.
A runtime error occurs as the program is being executed, such as dividing a number by 0.
A commonly used example is Java runtime Environment. This allows users to design a program on one platform (using the programming language java) which allows the finished program to then be run on many other systems.
A runtime environment enables the tools above such as trace and breakpoint to be used.