This week in computing we learnt about:
- High Level Language Programming Constructs. (HLL)
A macro is a function which is recorded by the user. The user records a series of key presses and then assigns the set of key presses to a keystroke. This will perform all the key presses at once. This means that this set of key presses can be played back as many times as the user needs to at a later.
Scripting is basically the same as a macro but the only difference is that the instructions are already programmed into the application. The user just has to choose what he/she wants to happen.
Benefits of Macros/Scripting
- Complex commands can be carried out by a single keystroke.
- More advanced users can set up pre-defined macros for beginners to make the application more simple.
- There is more flexibility and functionality from an application which macros/ scripts can be created.
- The user interface can be easily customized.
If a computer program is complex, it may be broken down into smaller, manageable pieces of code. This means the program is modular.
A subroutine is a block of code which needs to be passed a paramneter and can be called back into the main program by typing the subroutines name. This saves the programmer time as they don’t have to copy and paste the code and they can be specifically designed.
In the game pacman, there are four ghosts. The movement rules for each ghost are the same, but the programmer doesnt want to have to copy and paste the same code four times. It would make more sense to create a subroutine.
Example of subroutine code (move-ghost)
SUBROUTINE: move-ghost, (GhostName)
IF GhostName at edge of wall THEN
Change GhostName direction
move GhostName in current direction
After the subroutine is created. For it to work it has to be called. Once it is called, it must be past a parameter, in this case it is one of the four ghosts. The parameter being past is a string variable (the ghosts name) When the parameter is past the subroutine will execute the code on the chosen ghost. For example the ghost “PINKY” needs to be moved:
move-ghost (“PINKY”). Once this is called in the program. The subroutine will execute passing the parameter “PINKY”
Procedures and Functions.
There are also two types of subroutines a procedure and a function.
- Procedure produces an EFFECT
- Function produces a VALUE
In the example above the subroutine is a procedure as it produces an effect. the effect is the moving of the ghost.
There are two types of parameters. An actual parameter and a formal parameter.
An Actual Parameter is a parameter which is passed into the subroutine when it is called from another part of the program.
A Formal Parameter is a parameter that is used withing the subroutine definition.
There are two ways that a parameter can be passed, by reference or by value.
When the parameter is passed by reference, the value of the parameter is changed when it is passed through the subroutine.
When it is passed by value, the value of the parameter is not changed when it is passed through.
High Level Language Constructs (High Level Language vs Low Level Language).
A High Level Language (HLL) uses everyday language to make programming easier. Its features include arithmetic functions which instuctions can be written using the appropriate symbols ( +,-,*,/,^). There are also built in functions and these can be used as subroutines if necessary. One HLL instruction translates into several machine code instructions. A Low Level Language (LLL) is one that which humans will find difficult to understand, such as binary. It is much easier to write a program in HLL but a program written in LLL will run much faster as it is more efficient.
High Level Programming Constructs.
- Conditional Statements – IF,THEN,ELSE
- CASE Statements – a more compact version of a Conditional statement.
- Nested Loop – a loop within a loop.
- Conditional Loop – Repeats until a condition is met.
- Input Validation – Makes sure the users input is acceptable.