Syllabus Lesson 139 of 141 · Ten doors and the field kit
Ten doors and the field kit

Door 3: three layers of settings

Why it matters By now you have a toolbox: reframes, indexes, forgetting rules, event logs. The last door checks that you still know when to leave the toolbox shut.

A web app has three layers of settings: the product defaults, the team's choices and the user's own. Every request works out the effective settings. The app serves about 50 requests a second, and each layer is a flat dict of about 30 keys (text, numbers, booleans), loaded from the database with the user.

It sounds like it might want a cache, a class, or a layered config library. Read the numbers before deciding.

Your turn

Write effective_settings(defaults, team, user). Return a new dict with exactly the keys of defaults; each value comes from user if the key is there, else from team, else the default. Keys not in defaults are ignored. False, 0 and "" are real values and still win. Do not change the dicts you are given, and callers may change the dict you return. Rule: your whole code may have at most 60 syntax nodes (code_size).

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.