LO: Structure programming, the concepts of efficient code
Fundamentals of structured
programming
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Before /5
Fundamentals of structured programming
After /5
• LO: Structure programming, the concepts of efficient code
Success Criteria
• Explain what is structured programming and the reasons for it
• Demonstrate how to write good, efficient and easy to read code.
Success Criteria
Todaywhat
Explain we are practising the
is structured ACP of Analysing
programming and thebyreasons
the ability
fortoit work
Demonstrate how effectively
to writewithin
good, the rules and
efficient of a easy
domain
to read code.
LO: Structure programming, the concepts of efficient code
The best formed and most readable code…
• If you want to be a good programmer (and get good marks in the
exam) then you have to ensure that your code is easily read by other
people.
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Things to do when coding
1. Use procedures that execute a single task.
2. Use procedures / functions with interfaces
3. Use sensible variable data types
4. Meaningful Identifier names
5. Use sensible procedure / function names.
6. Stick to one naming convention
7. Don’t make names too long
8. Indent your work
9. Use comments
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Indenting your work example
• A lot of programming environments help to indent your code
automatically and you should be able to find one for the language you
are using.
• Indenting helps people to read and understand your code quickly as it
clearly shows the structure of functions, procedures, selection and
iteration statements.
• For example the following could be hard to read:
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Indenting your work example
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Commenting example
• Some of the best written code doesn't need comments because if you
have structured it correctly and used all the proper naming
conventions it should be pretty easy to read. However for the code
you are writing you should put some comments to explain what each
section does.
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
The advantages of the structured
approach
• Easy to read and fix code
• Problems broken down into easy to manage chunks
• Procedures / Functions are reusable, you can use them in different
projects.
• You can test modules individually.
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
What might be considered wrong about
the use of this subroutine?
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
• The sub routine is performing multiple function: it calculates the total
AND the average.
• Functions/procedures should only perform one task at a time. You
could replace the above with two subroutines:
• calcAvg
• calcTotal
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
• List three reasons for using functions and procedures to structure your
code:
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
• List three reasons for using functions and procedures to structure your
code:
• Answer :
• You can re-use the code
• You can test parts of the code individually
• The code is easier to read and understand
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Give three structured programming
techniques that could be used to improve the
code…
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
• Correct use of indentation
• Sensible variable names Eg cheesy used to store the age.
• Use comments
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Activity 01
• Read and complete the tasks from pages 28 -34 and answer all task
• Self-assess using answer sheet and make improvements in purple
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Activity 2
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Structure programming review - Activity
• Pass your code on to a peer.
• Your peer will now respond and give advice based on the structure
programming
• Add their feedback to your class notebook and make the
improvements
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Challenge Activity
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Challenge Extension
• Extend your program further by creating a user profile. The users
details will be recorded in an array and the functions you have created
can be applied to populate certain fields in the record. Such as BMI.
• The rest of the record should include; Name, Address, BMI, height,
weight and goal.
• HINT:- You will need to use a structure
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.
LO: Structure programming, the concepts of efficient code
Plenary
• Outline 3 ways to structure your code.
• Give the benefit of each of these.
• How would each of these be a benefit is industry?
Success Criteria
Explain what is structured programming and the reasons for it
Demonstrate how to write good, efficient and easy to read code.