Syllabus Lesson 64 of 141 · Data models that bend
Data models that bend

Ids, not names

Why it matters Using a name as the key is the shortest model, and names are the least stable thing about people and teams. Renames, reorganisations and two people called the same thing are routine, not edge cases.

An internal tool lists which people are in which team. Today's request: add teams, add people to teams, list a team's members. HR mentions that a reorganisation is coming, teams will be renamed, people move, and there are already two engineers called Sam Lee.

Stable id: a value that names a thing for its whole life and never changes, even when every visible property does.

Your turn

Today's request. Write new_org(), add_team(org, name) (returns a team id), add_person(org, name, team) (team is a team id; returns a person id) and members(org, team) (sorted list of member names). Ids can be any value you choose.

What is coming. Names will change and repeat. Hidden change requests will call these, so write them now as well: rename_team(org, team, new_name), team_name(org, team), rename_person(org, person, new_name) and move_person(org, person, team). Two people can share a name, and a new team may reuse a name an old team had. Every id you have handed out must keep working after any of these.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.