Programming 3- module 13) Flashcards
What are subroutines?
Blocks of code that can be put anywhere in a program + ‘called’ in body of code just by naming them.
What is code written without subroutines often called?
‘Spaghetti code’.
Why is code written without subroutines often called ‘spaghetti code’?
As so much longer.
Why is structured programming so helpful?
Breaks any big task into little 1s (decomposition) makes tasks more achievable.
Updating code made easier as subroutines can be edited individually.
Using code modules or subroutines (1 for each part of the task) makes easy to see which part of code does specific task.
What are the advantages of subroutines?
Iteration.
Keeps code shorter.
Easier to test large tasks.
Can access + use any variable from main code without having to refine it.
How does iteration help as an advantage of subroutines?
Code can be written once, then used again.
How does keeping the code shorter act as an advantage of subroutines?
Only writing code once for subroutine. No matter how many times need it, code can be considerably shorter.
How does the code being easier to test large tasks act as an advantage for subroutines?
If decomposed into smaller subtasks. Can be easy to test 1 module- or subroutine- at a time.
When programming what is it important to remember?
Code using subroutines not linear so can be placed at any point within a program.
Subroutines need to be clearly identifiable.
Planning ahead really important.
What are translators usually included within?
Programming software.
What 3 types of translator are there?
Assemblers.
Interpreters.
Compilers.
What is the purpose of an assembler?
Translates assembly language to machine code so fewer errors in translation.
What is the advantage of assembler?
Far closer to machine code, so fewer errors in translation.
What are the disadvantages of assembler?
Very device specific with limited instructions available.
More difficult to code + complex tasks require long programs.
What is the purpose of a compiler?
Translates program that programmer wrote into machine code in 1 sweep before program run.