Search Header Logo
Y11 CS Unit 10 T4 Maintainable programs

Y11 CS Unit 10 T4 Maintainable programs

Assessment

Presentation

Computers

12th Grade

Practice Problem

Easy

Created by

Michael Harrington

Used 3+ times

FREE Resource

15 Slides • 14 Questions

1

media

Objectives

• Understand how to create maintainable programs

including the appropriate use of:

• Meaningful identifiers

• Comments

• Procedures and functions

• Relevant and appropriate commenting of syntax

• Use meaningful identifiers for:

• Variables and constants

• Arrays

• Procedures and functions

2

Multiple Choice

Question image

This topic may come up in the exam.

If you read this carfully you should be able to get 90% +

How will you ensure a good grade in the GCSE in 3 months?

1

Guess the answers

2

Do not bother reading the slides

3

Read carefully as this time is your exam revision on this topic

4

Just chat and not pay attention

3

Fill in the Blank

Show you know the objectives:

including the appropriate use of <?> identifiers

4

5

Fill in the Blank

Show you know the objectives:

including the appropriate use of Procedures and <?>

6

Fill in the Blank

Show you know the objectives:

Use meaningful identifiers for <?> and constants

7

media

Maintainable programs

Unit 10 Advanced programming and databases

Starter

• Think about programs you have

looked at and programs that
you or your friends
have written

• What features made them

easy or hard to read, edit
and understand?

8

Open Ended

Think about programs you have looked at and programs that you or your friends have written.

What features made them easy or hard to read, edit and understand?

9

media

Maintainable programs

Unit 10 Advanced programming and databases

Starter

• Programs are easy to maintain (read, understand

and make changes to) when

• They use meaningful identifiers for variables, constants,

arrays, procedures and functions

• They have useful comments that are relevant and appropriate

• They make use of procedures and functions

• Another area that helps to make programs easy to

maintain is:

• Good use of indentation and whitespace

10

media

Maintainable programs

Unit 10 Advanced programming and databases

Meaningful identifiers

• The two programs below are the same algorithm

• Which is easier to understand? Why?

INPUT a
INPUT b
INPUT c
d <- a + b + c
e <- d / 3
OUTPUT e

INPUT num1
INPUT num2
INPUT num3
total <- num1 + num2 + num3
average <- total / 3
OUTPUT average

11

Multiple Choice

Question image

The two programs are the same algorithm

Which is easier to understand?

1

Left

2

Right

12

Open Ended

Question image

The two programs are the same algorithm

Which is easier to understand?

Why is your chosen one easier?

13

media

Maintainable programs

Unit 10 Advanced programming and databases

Meaningful identifiers

• The two programs below are the same algorithm

• Which is easier to understand? Why?

• It is important to use meaningful names for

variables, constants, arrays, functions & procedures

• This makes code easier to read and understand

INPUT a
INPUT b
INPUT c
d <- a + b + c
e <- d / 3
OUPTUT e

INPUT num1
INPUT num2
INPUT num3
total <- num1 + num2 + num3
average <- total / 3
OUTPUT average

14

media

Maintainable programs

Unit 10 Advanced programming and databases

Maintainable programs

• Programs need to be maintained

• This will be to improve the code, fix bugs or add new features

to the program

• It may be carried out by the original programmer or different

programmers

• It is important that programs are written in a way to

make them easily maintainable. This includes:

• Using meaningful identifiers

• Adding comments

• The use of functions and procedures

• Indentation

15

media

Maintainable programs

Unit 10 Advanced programming and databases

Commenting

• Comments in code help other programmers to

understand your code

• They also help you understand your code when you go back

to it at a later time

• Which parts of programming code tend

to be commented?

• Which parts are typically not commented?

16

media

Maintainable programs

Unit 10 Advanced programming and databases

Commenting

• Comments are usually written for:

• Parts of a program/algorithm that are difficult to understand

• At the start of a function or procedure to explain what it does

• Comments usually aren’t written for:

• Every line of code

• To explain parts of code that are obvious

• To explain easier syntax used in the programming language –

programmers are expected to look up and learn parts of the
language that they don’t understand

17

Reorder

Reorder the following about Comments

Comments are usually written for: Parts of a program/algorithm that are difficult to

understand. At the start of a function or procedure to explain what it does. Comments

usually aren’t written for: Every line of code. To explain parts of code that are

obvious. To explain easier syntax used in the programming language – programmers

are expected to look up and learn parts of the language that they don’t understand.

1
2
3
4
5

18

media

Maintainable programs

Unit 10 Advanced programming and databases

Procedures and functions

• Subroutines include functions and procedures

• Well written subroutines will take inputs (through parameters)

and if necessary return a value

• They should be written in a modular so that they can be

reused multiple times in the program or by other programs

• The two programs below are for a function that works out the

area of a circle. Which is more easy to reuse and help create
maintainable code?

FUNCTION circle(radius)

area = 3.14 * radius^2
RETURN area

ENDFUNCTION

FUNCTION circleFive()

area = 3.14 * 5^2

RETURN area

19

Drag and Drop

Question image
Subroutines include ​
and procedures.

Well written subroutines will take ​
(through parameters) and if necessary return a ​


They should be written in a ​
so that they can be reused multiple times in the program or by other ​
The two programs below are for a function that works out the area of a circle. Which is more easy to reuse and help create maintainable code?

Drag these tiles and drop them in the correct blank above
functions
inputs
value
modular
programs
ENDFUNCTION
radius
parameters
area

20

media

Maintainable programs

Unit 10 Advanced programming and databases

Using subroutines

• The program on the left takes any sized radius as

an input

• This means that it is reusable many times in the program and

in other programs

• This will make a larger program easier to maintain as there

will be just one function to calculate the area of a circle

FUNCTION circle(radius)

area <- 3.14 * radius^2

RETURN area

FUNCTION circleFive()

area <- 3.14 * 5^2

RETURN area

21

media

Maintainable programs

Unit 10 Advanced programming and databases

Indentation

• Look at the following pseudocode:

tables <- 12
rows <- 12
FOR i <- 1 TO tables
FOR j <- 1 TO rows
answer <- i * j
NEXT j
NEXT i
OUTPUT i, "x", j, "=", answer

• Why would the use of indentation improve it?

Why may indentation be essential in some languages?

22

Open Ended

Question from the previous slide:

Why would the use of indentation improve it?

23

Open Ended

Question from the previous slide:

Why may indentation be essential in some languages?

24

media

Maintainable programs

Unit 10 Advanced programming and databases

Indentation

tables = 12
rows = 12
FOR i - 1 TO tables

FOR j = 1 TO rows

answer = i * j

NEXT j

NEXT i
OUTPUT i, "x", j, "=", answer

• Why would the use of indentation improve it?

Indentation makes it possible to easily see which lines of
code are part of different structures

• Why may indentation be essential in

some languages?

Some languages use braces { } to show where structures
start and end, but some, such as Python use indentation

25

media

Maintainable programs

Unit 10 Advanced programming and databases

Plenary

• The following code calculates the area of a triangle

• Look at the following and explain at least four improvements

that would make it more maintainable

FUNCTION triA(a, b)
c = 0.5 * a * b
RETURN c
ENDFUNCTION

OUTPUT triA(5, 3)

26

Multiple Select

The following code calculates the area of a triangle

Look at the following and select improvements that would make it more maintainable

FUNCTION triA(a, b)

c = 0.5 a * b

RETURN c

ENDFUNCTION

OUTPUT triA(5, 3)

1

Meaningful identifiers for the function name

2

Use of comments that are irrelevant and inappropriate

3

Indentation

4

Meaningful identifiers for the compiler to understand

5

Well spaced out for readability

27

Open Ended

Question image

Use SHIFT and ENTER for a new line!

Re write this function with the improvements that would make it more maintainable at least four improvements that would make it more maintainable

28

media

29

Multiple Choice

Question image

Which is correct for the previous code and as in the image?

10 marks for getting this correct

1
2
3
4
media

Objectives

• Understand how to create maintainable programs

including the appropriate use of:

• Meaningful identifiers

• Comments

• Procedures and functions

• Relevant and appropriate commenting of syntax

• Use meaningful identifiers for:

• Variables and constants

• Arrays

• Procedures and functions

Show answer

Auto Play

Slide 1 / 29

SLIDE