Planning the Logic First Saves the RebuildDefinitionAlgorithmA precise, ordered set of steps that solves a problem or finishes a task, written so anyone following it gets the same result.An algorithm is the plan itself, and code is only one way of writing that plan down.Typing code straight away means you are hunting a logic fault and a spelling fault at the same time, with no way to tell which one is biting.A flowchart takes about ten minutes and can be shown to a client who has never programmed anything.A drawn plan is also evidence for Developing ideas, because a finished program shows the answer and a plan shows the thinking.Fixing a wrong plan costs you one rubbed out arrow, while fixing the same fault after you have built it can cost half the program.Four Symbols Cover Almost Every FlowchartA terminator is a rounded box holding Start or Stop, and a flowchart has exactly one Start.A process is a rectangle holding one action, such as "set score to 0" or "turn LED on".A decision is a diamond holding a yes or no question, and it is the only symbol with two arrows leaving it.An input output symbol is a parallelogram for anything coming in or going out, such as "read button" or "display total".Arrows carry the order and always need a head, since a line with no direction tells the reader nothing.There is no special loop shape, because a loop is drawn as an arrow running back up to a symbol you have already passed.Common MistakeBoth exits from a decision diamond must be labelled Yes and No, and an unlabelled exit is the commonest flowchart mistake.Two arrows arriving at one symbol is normal, but two arrows leaving a process rectangle is always wrong.Drawing a Flowchart for a Real RoutineTake an automatic hand dryer, since it is small enough to draw on half a page and real enough to check against the one in the corridor.After Start, the first symbol is a parallelogram reading the infrared sensor.A diamond then asks "are hands detected", and the No arrow loops straight back to the sensor reading.The Yes arrow goes to a rectangle, "run the fan", and then to a second diamond asking "have hands been gone for 2 seconds".No loops back so the fan keeps running, and Yes goes to "stop fan" and then back up to the sensor reading.This chart has no Stop symbol at all, which is correct for a device that runs until someone unplugs it.HintWalk your finger round the finished chart pretending to be the machine.If your finger lands on a symbol with no arrow out, or a diamond with one exit, the chart is unfinished.Pseudocode Says the Same Thing in WordsPseudocode is the plan written as short English lines that have the shape of code without the fussy punctuation.The usual keywords are INPUT, OUTPUT, SET, IF, ELSE, WHILE, REPEAT and END, written in capitals so they stand out from your own words.Indentation carries real meaning, because everything inside an IF or a WHILE is shifted one step to the right.Nobody marks pseudocode for syntax, so SET or LET are both fine as long as you stay consistent inside one plan.Pseudocode handles what flowcharts show badly, such as eight straight steps in a row or a calculation three terms long.ExampleSET score TO 0INPUT answerIF answer = "b" THEN SET score TO score + 1OUTPUT scoreFlowchart or Pseudocode: Pick by What You Need to ShowFlowcharts win when the logic branches, because a labelled diamond is easier to follow than three IFs nested inside each other.Pseudocode wins when the logic is long and mostly straight, since twenty rectangles stacked in a column say nothing a numbered list would not.A flowchart is the better thing to put in front of a client during an interview, since it needs no explanation of what SET means.Pseudocode is faster to change, because you retype one line rather than redrawing a page.Many design folders carry both, with a flowchart for the overall shape and pseudocode for the one section that is fiddly.Exam techniqueDate your first flowchart and keep it even after you change the design, because the change is itself the evidence of development.Annotate the kept version with one line per change saying what went wrong.A clear photograph of a hand drawing is fine for your ePortfolio, so do not spend an hour redrawing it in software.A Plan Is Only Good If You Test It on PaperRun three sets of made up data through the plan before you write any code: one normal value, one edge value and one silly value.For the hand dryer that is hands held still, hands removed at exactly 2 seconds, and someone waving a hand through in half a second.Write the result you expect beside each one first, then follow the chart and see whether it agrees.The half second wave is the one that catches people out, because a chart with no minimum run time switches the fan on and off in a blink.Trace tables make this paper testing formal, and the debugging and testing article covers them.Active recallWhich flowchart symbol is the only one with two arrows leaving it, and how are they labelled?Why does the hand dryer flowchart have no Stop symbol?What does indentation do in pseudocode?Give one situation where pseudocode is the better choice than a flowchart.Name the three kinds of test data you should walk through a plan.