Part 5, Modular Programming Flashcards
what is modular programming also known as
modular programming is also known as component based programming
explain what modular programming is
modular programming means splitting a program up into smaller modules or components
name four main benefits of modular programming
- easier to create
- less error prone
- readability
- reusability (in same or external program)
why are modular programs easier to create
modular programs are easier to create because they can be worked on in small independent sections. ultimately these “sections” or components will make up a tiny piece of the program
why are modular programs less prone to error
modular programs are less prone to error because each component can be created and tested one piece at a time this greatly reduces bugs being created within the program.
modular programs also have the benefit of aiding in debugging because each component can be tested individually
why are modular programs easier to understand
because modular programs are broken up into smaller subtasks this makes reading the code easier. and following the stream of execution much more obvious
what are three main rules for a module when implementing modular programming
- a module should have a specific and meaningful task
- the name of the module should reflect what the module does
- modules should be commented
what five pieces of information might be given in a modules comment/specification
- explain what the module does
- explain how its inputs are used
- explain any variables it sets
- give information of any dependencies it has
- give an example of it in action
what is a pre condition
a pre condition is a condition that must be met in order for a module to operate correctly
this must be mentioned within its specification
“number_input must be in numbers_list”
is written within a modules comments and is part of its specification
what is this an example of
“number_input must be in numbers_list”
is an example of a modules pre condition
your told to factor out a chunk of code within your program
what does the term “factor out” mean
“factor out” means taking a block of code out of the main script and creating a separate subtask/module for it. without changing what the script does
what is meant by re factoring code
re factoring code means rewriting/restructuring code to make it simpler to read or more efficient without changing what the program does
what does the term monolithic mean
monolithic is a term used to describe code that is written in a non modular fashion
this means the code may all be written within one script
what are 5 possible drawbacks of monolithic code
monolithic code can be
- lengthy
- complicated
- prone to errors
- harder to code
- low readability
when designing the algorithm from the specification you see that modular programming may be helpful
how can you show that you will be using modular programming within the algorithm
when you spot a subtask that can be a module
- mark the subtask {subtask 1} for example
- write out the specification for the subtask in a separate box
- keep the subtask marked in main algorithm with an arrow pointing to its boxed specification