I’ve been thinking about two different approaches to writing code and I’m not sure which one to follow.
One approach says we should create modules that hide complexity behind simple interfaces. The user doesn’t need to know much to use them. This comes from John Ousterhout’s book on software design philosophy.
The other approach from Robert Martin’s Clean Code says we should break everything into small focused functions. This usually means more interfaces to work with.
I always liked the small functions approach because it worked well for me. But recently I had trouble with a component library that had too many options. Here’s what I mean:
Complex component with many parts:
import { MenuSystem } from "ui-library";
function MyMenu() {
return (
<MenuSystem.Container>
<MenuSystem.Button />
<MenuSystem.Overlay>
<MenuSystem.Panel>
<MenuSystem.Title />
<MenuSystem.Option />
<MenuSystem.Section>
<MenuSystem.Option />
</MenuSystem.Section>
<MenuSystem.Checkbox>
<MenuSystem.Check />
</MenuSystem.Checkbox>
<MenuSystem.Divider />
</MenuSystem.Panel>
</MenuSystem.Overlay>
</MenuSystem.Container>
);
}
Simple component that hides complexity:
<SimpleMenu
title="User Actions"
items={[
{ url: '/profile', text: "Edit Profile" },
{ url: '/settings', text: "Settings" },
{ url: '/logout', text: "Sign Out" },
]}
/>
The first one gives you more control but it’s harder to learn and use. The second one is much easier but less flexible.
How do you decide when to make things simple vs when to break them into smaller pieces? I’m looking for practical advice on this trade-off.