I’ve been thinking about two different ways to write code after reading some books and running into issues on a recent project.
One approach says to build modules that hide complexity behind simple interfaces. The other approach (like in Robert Martin’s work) says to break everything into tiny, focused functions.
I ran into this problem with a component library recently. Their MenuDropdown was super flexible but really hard to use:
import { MenuDropdown } from "ui-lib";
export const MyMenu = () => (
<MenuDropdown.Container>
<MenuDropdown.Button />
<MenuDropdown.Overlay>
<MenuDropdown.Header />
<MenuDropdown.Option />
<MenuDropdown.Section>
<MenuDropdown.Option />
</MenuDropdown.Section>
<MenuDropdown.Toggle>
<MenuDropdown.CheckIcon />
</MenuDropdown.Toggle>
<MenuDropdown.Divider />
<MenuDropdown.Pointer />
</MenuDropdown.Overlay>
</MenuDropdown.Container>
);
Compare that to something simpler:
<SimpleMenu
title="User Actions"
items={[
{ url: '/profile', text: "Edit Profile" },
{ url: '/settings', text: "Settings" },
{ url: '/logout', text: "Sign Out" },
]}
/>
The first one gives you tons of control but requires learning so many parts. The second one is way easier to use for basic cases.
How do you decide when to favor simple interfaces that hide complexity versus breaking things down into smaller pieces? I keep going back and forth on this.