Code Complexity
Time 60 mins

Difficulty Intermediate
Prerequisites Thinking Procedurally
Departments Science
Authors Sandra Kuipers
Groupings Individual
Minimum Year Group None


What causes code complexity, and how can we avoid it? This unit looks at the ways we can write code that is easier to read and maintain.


This work is shared under the following license: Creative Commons BY-SA-NC


Learner Outcomes
Students will:
  • ...
Competency Focus
  • ...
Interdisciplinary Connections
  • ...
What was successful? What needs changing? Alternative Assessments and Lesson Ideas? What other Differentiation Ideas/Plans could be used?
  • ...
Any CC attribution, thanks, credit, etc.

This page requires you to be logged in to access it. Please login and try again.
5 mins
Getting Started
15 mins
Under the Hood
Digging In
  • Before long, the Universal Paperclips game gets pretty complex.

  • Most of the game happens in two files:
  • Spend a few minutes scrolling through the code. What do you see?
  • Don't read it all (there's 5546 lines in main.js alone!)
  • The idea is to get a sense of the functions, conditionals and variables used.
10 mins
Software Architecture
Digging In
  • What did you think of the Universal Paperclips code?
    • Easy to understand?
    • Hard to understand?
  • Don't worry if you had trouble reading it.
  • I didn't share the code because it's a perfect example of how to write good code.
  • But, its not all bad either. We can learn a lot by reading other people's code.

  • The good:
    • The game logic is separated out into functions.
    • Nested only one or two levels deep.
    • Well named variables and functions.
    • For the most part we can understand what each function does.
    • Many of the conditionals are easy to read, for example: if(funds >= wireCost)
  • The bad:
    • It's HUGE! Generally something this big we would split into smaller files.
    • There's conditionals, functions and variables mixed everywhere.
    • We've played the game, so we know the code works, but it's borderline spaghetti code.

Image from The Evolution of Software Architecture by Benoit Hediard

  • According to this chart, where would you classify the Universal Paperclips code?
  • Perhaps somewhere between spaghetti and lasagna?
  • Modern programming is all about the ravioli.
  • Small, bite-sized, modular code.
30 mins
Writing Pseudocode
There are no records to display.
Powered by Gibbon v27.0.00dev

Founded by Ross Parker at ICHK Secondary | Built by Ross Parker, Sandra Kuipers and the Gibbon community
Copyright © Gibbon Foundation 2010-2024 | Gibbon™ of Gibbon Education Ltd. (Hong Kong)
Created under the GNU GPL | Credits | Translators | Support