Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OSP task 2 (1 of 3): Build, save versions and review code

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Two people, one file

Sam and Aisha both change the same file. Sam saves at 10:00. Aisha saves at 10:05. Sam's work is gone.

Teams solve this with version control. Version control is a tool that keeps every version and joins changes safely. Even when you work alone, it protects you.

Key words

WordWhat it meansExample
Version controlA tool that keeps every saved version of your work.Git
RepositoryA folder that holds your project and its history.hillside-tool
CommitA saved step in the history, with a short message.Add leave_waiting_list
BranchA separate line of work that you join back later.waiting-list
Pull requestA request to join your branch into the main one, so others can review it.Add the waiting list
Code reviewAnother person reads your code and gives feedback.a checklist
Pair programmingTwo people work at one computer. One types and one watches.one person types, one person checks
MergeJoin the work of a branch into the main version.join waiting-list into main
FunctionA named piece of code that does one job.next_in_line()
ReadabilityHow easy the code is for a person to read.clear names

The cells students fill in are left blank in this preview.

Match the word to its meaning

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The Git commands in this lesson

CommandWhat it does
cd hillside-toolGoes into the folder
echo "text" > waiting.pyMakes a file called waiting.py with that text in it
git init hillside-toolMakes a new repository in a folder called hillside-tool
git statusShows which files changed
git add waiting.pyChooses a file for the next commit
git config --global user.name "Student"Tells Git your name, so each commit shows who made it
git config --global user.email "[email protected]"Tells Git your email, so each commit shows who made it
git commit -m "message"Saves a step with a short message
git log --onelineShows the history, one line each
git checkout -b waiting-listMakes a new branch and moves to it

The cells students fill in are left blank in this preview.

Start the lab first

Note

Press Start the lab on the bar at the top of this lesson. Wait until it says it is running. Each Run button types a command into your lab terminal. The commands work in a new practice folder, so nothing important can break. Never run a command you do not understand.

Step 1: make a repository

Command
git init hillside-tool

A command for the lesson’s lab terminal. It is shown here and not run.

Step 2: go into the folder

Command
cd hillside-tool

A command for the lesson’s lab terminal. It is shown here and not run.

Step 3: make a file

Command
echo "# Hillside waiting list" > waiting.py

A command for the lesson’s lab terminal. It is shown here and not run.

Step 4: ask Git what it sees

Command
git status

A command for the lesson’s lab terminal. It is shown here and not run.

What did you see?

Have a go

What did you see?

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Step 5: choose the file

Command
git add waiting.py

A command for the lesson’s lab terminal. It is shown here and not run.

Step 6: tell Git your name

Command
git config --global user.name "Student"

A command for the lesson’s lab terminal. It is shown here and not run.

Step 7: tell Git your email

Command
git config --global user.email "[email protected]"

A command for the lesson’s lab terminal. It is shown here and not run.

Step 8: save a step

Command
git commit -m "Add the waiting list file"

A command for the lesson’s lab terminal. It is shown here and not run.

Step 9: read the history

Command
git log --oneline

A command for the lesson’s lab terminal. It is shown here and not run.

What did you see?

Have a go

What did you see?

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Step 10: start a branch

Command
git checkout -b waiting-list

A command for the lesson’s lab terminal. It is shown here and not run.

From a branch to the main version

flowchart LR
  main[Main version] --> branch[Make a branch]
  branch --> work[Work and commit]
  work --> pr[Pull request]
  pr --> review{Review: any problems?}
  review -->|yes| work
  review -->|no| merge[Join into main]

Check: version control

Have a go

Check: version control

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Task 2 practice: build the waiting list

Task 2 practice. Build two more waiting list functions. join_waiting_list is finished. next_in_line gives the first member waiting for a court and hour, or None. leave_waiting_list removes a member and gives back True or False. Commit after each function if you use Git. Press Run Tests to check your work.

Code: python
def join_waiting_list(waiting, member, court, hour):
    # Finished for you. waiting is a list of dictionaries.
    place = 0
    for one in waiting:
        if one["court"] == court and one["hour"] == hour:
            if one["member"] == member:
                return 0
            place = place + 1
    waiting.append({"member": member, "court": court, "hour": hour})
    return place + 1


def next_in_line(waiting, court, hour):
    # Give back the name of the first member waiting for this court and hour.
    # Give back None if nobody is waiting for it.
    return 0


def leave_waiting_list(waiting, member, court, hour):
    # Remove this member's entry for this court and hour.
    # Give back True if it was removed, False if it was not there.
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

Three ways to review code

WayWhat happensHow formal
Pair programmingTwo people work at one computer. One types, one watches and thinks.Very informal
Informal walkthroughYou show your code to a teammate and explain it line by line.Informal
Formal inspectionA planned meeting with set roles. The faults are written down.Formal

The cells students fill in are left blank in this preview.

A kind and useful code review

Look forSay it like this
A name that is unclearI did not understand what x means. Could it be called place?
A missing checkWhat happens when the list is empty? Maybe add a test.
Good workThe function does one job and is easy to read. Well done.
A repeated blockThese two parts look the same. Could one function do both?

The cells students fill in are left blank in this preview.

Talk about the code, not the person

Tip

Say "this line" and not "you". Be exact. Give one good point and one improvement. When you get feedback, say thanks, ask if you do not understand and decide what to change.

Task 2 practice: commits and a review

Part A: write four commit messages for the four steps of building the waiting list: start the file, then add join_waiting_list, next_in_line and leave_waiting_list. Each should say what was added, in one short line. Part B: read the function leave_waiting_list that you wrote. Write a short code review of it as if you were a teammate: one good point, one thing to improve and one question. Part C: write two sentences about how you would act on feedback from a teammate.

A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Final check

Have a go

Final check

6 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.