interface User {
name: string;
age: number;
role: 'admin' | 'user';
}
function saveUser(user: User) {
// ...write to DB
}
This is slightly better. The caller needs to understand or figure out only one thing, the User
interface. There is no order of parameters to worry about, and the notion of isAdmin
is much clearer (and expandable) as role
.
Page-Jones created an entire taxonomy of connascence to describe these kinds of code relationships and help us manage them. Connascence also helps us think about two crucial dimensions: how strong the coupling is, and how far apart the coupled pieces live. Coupling between two routines in the same object is normal. But when coupling spans modules or services, it becomes a serious problem.
Connascence gives you a sharper vocabulary to describe coupling, and a new way to look at your code. Next week, we’ll dive into the taxonomy and start naming the different kinds of coupling you’re already living with.