Want to keep learning?

This content is taken from the Coventry University's online course, Get ready for a Masters in Data Science and AI. Join the course to learn more.

Building complexity in your design

The next step of making a program is breaking down the processes of the program into a medium that is easy for you and anyone else reading it to understand.

One medium that you could use is flowcharts. This is a more visual and structured way to represent the steps of a program. By ‘steps’, we mean the different actions and decisions that will be made. They also make it easier to visualise any errors that you may encounter later in the program.

The easiest way to get started is to copy over the steps from your pseudo code and place each one into a block in a flowchart, as in the example below, which continues the tea-making scenario. The flowcharts below use an internationally recognised set of symbols.

Flowchart showing: Put tea bag in mug [rectangle] - Add water [rectangle] - Add milk [rectangle] - Add sugar [rectangle] - Serve [rectangle]

Now you have the basics of the program design ready to work with, it’s time to look at the additional, more complex steps that were lacking in the pseudo code. We need to ask questions within the program like has the kettle boiled? Do they want sugar? Do they want milk?

Flowchart showing: Put tea bag in mug [rectangle] - Is the kettle boiled? [diamond] - No - Boil kettle [rectangle] - Return to question - Is the kettle boiled? [diamond] - Yes, continue - Add boiled water [rectangle] - Milk? [diamond] - Yes - Add milk [rectangle]. No, continue - Sugar? [diamond] - Yes - Add sugar [rectangle]. No, continue - Serve [rectangle]

In the step above, we have added some decisions (diamond shape) and a loop. The decisions branch off depending on the answer to the question. Like in this example, we ask if the user wants milk. If they do, we add milk. If not, the program continues onto the next decision point.

Flowchart highlighting questions and decisions aspect of chart - branches: Put tea bag in mug [rectangle] - Is the kettle boiled? [diamond] - No - Boil kettle [rectangle] - Return to question - Is the kettle boiled? [diamond] - Yes, continue

We can also create loops, where we can halt our program until a condition is met. We do this when checking if the kettle has been boiled at the start of the program. This part will run forever until either the program is stopped or the kettle is boiled.

Flowchart highlighting new complexity of questions and decisions - loops: Put tea bag in mug [rectangle] - Is the kettle boiled? [diamond] - No - Boil kettle [rectangle] - Return to question - Is the kettle boiled? [diamond] - Yes, continue

But is there any water in the kettle to boil? How much milk and sugar does the user want? Questions always lead to more questions, which helps you expand your program design to account for more and more conditions.

Flowchart showing: Put tea bag in mug [rectangle] - Is there water in the kettle? [diamond] - No - Add water to kettle [rectangle] - Return to question - Is there water in the kettle? [diamond] Yes, continue - Is the kettle boiled? [diamond] - No - Boil kettle [rectangle] - Return to question - Is the kettle boiled? [diamond] - Yes, continue - Is the mug full of water? [diamond] - No - Add boiled water to mug [rectangle] - Return to question - Is the mug full of water? [diamond] - Yes, continue - Milk? [diamond] - Yes - Add milk [rectangle] - More milk? [diamond] - Yes - Add milk [rectangle]. No, continue - Sugar? [diamond] - Yes - Add sugar [rectangle] - Add more sugar? [diamond] - Yes - Add sugar [rectangle]. No, continue - Serve [rectangle]

Notice how, just by asking ourselves questions, we have expanded our five-step pseudo code into a pretty solid program design, whilst maintaining a simple structure that the computer will be able to understand when we finally start converting our design to code.

Asking questions is one of the main parts of programming. You may even go as far as to ask, ‘have you paid the electricity bill so the kettle can boil?’ It may feel silly going into this much detail, but this is what programming is like. The more decisions we implement and account for, the more fool-proof our program will be. We have to remember that the computer can only do what you tell it to do.

Your task

Review our tea-making program above and consider what other conditions we may need to account for in the design.

Identify at least five different steps/decisions that could be added to our program to improve it further and discuss with your fellow students in the comments area below.


References

Gliffy. (2020, November 15). Guide to flowchart symbols, from basic to advanced. Perforce. https://www.gliffy.com/blog/how-to-flowchart-basic-symbols-part-1-of-3

Share this article:

This article is from the free online course:

Get ready for a Masters in Data Science and AI

Coventry University