Sub-process

From Computer Science Wiki
Explaining sub-processes[1]

The role of a sub-process is to make a problem easier to solve, especially when a problem requires repetition. A sub-process is synonymous with a function.

What is a sub-process[edit]

A sub-process is a named-part of a larger process. This sub-process can be called many times, like a function. A sub-process accepts input, processes the input, and returns a result.

Example[edit]

Imagine we had a program which described monsters. The description of a monster can be ONLY ONE OF the following:

  1. fluffy
  2. spikey
  3. slimy
  4. scary

If we had 10 different monsters would it make sense for us to write this conditional 10 times?

def description_of_monster(value):
    if value == 1:
        return "fluffy"
    elif value == 2:
        return "spikey"
    elif value == 3:
        return "slimy"
    else:
         return "scary"

... of course not! It makes much more sense to create a sub-process so we can avoid repetition, increase efficiency, make our code more understandable.

Standards[edit]

These standards are used from the IB Computer Science Subject Guide[2]

  • Explain the role of sub-procedures in solving a problem.

References[edit]

  1. http://www.flaticon.com/
  2. IB Diploma Programme Computer science guide (first examinations 2014). Cardiff, Wales, United Kingdom: International Baccalaureate Organization. January 2012.