I’ve been thinking about two different approaches to writing code after working with some tricky UI components lately.
On one side, there’s the idea from A Philosophy of Software Design that says we should create modules with simple interfaces that hide all the messy details inside. The user doesn’t need to know how things work internally.
On the other side, Clean Code tells us to break everything into tiny, focused functions. This often means more functions to deal with, which can feel like the opposite approach.
I ran into this issue recently with a menu component library. The component had way too many options and parts:
import { MenuSystem } from "ui-toolkit";
export default () => (
<MenuSystem.Container>
<MenuSystem.Button />
<MenuSystem.Overlay>
<MenuSystem.Panel>
<MenuSystem.Header />
<MenuSystem.Option />
<MenuSystem.Section>
<MenuSystem.Option />
</MenuSystem.Section>
<MenuSystem.Toggle>
<MenuSystem.Check />
</MenuSystem.Toggle>
<MenuSystem.Divider />
<MenuSystem.Pointer />
</MenuSystem.Panel>
</MenuSystem.Overlay>
</MenuSystem.Container>
);
Compare that to something much simpler:
<ActionMenu
title="User Settings"
items={[
{ url: '/profile', text: "Edit Profile" },
{ url: '/security', text: "Change Password" },
{ url: '/remove', text: "Remove Account" },
]}
/>
The first approach gives you tons of control but takes forever to learn. The second one is way easier to use but less flexible.
How do you decide when to go with simple interfaces versus breaking things into smaller pieces? What’s your strategy for making this choice?