Cover image for The Use/Reuse paradox explained

The Use/Reuse paradox explained

codingunicorn profile image Coding Unicorn πŸ¦„ ・1 min read

The Use/Reuse Paradox

When designing code, it's important to understand who will consume it. Do you design it for a single specific use-case? Or do you want to cover many different use cases?

βœ… You can pluralise English words with a single loc:

function pluralize(amount, item) {
  return amount === 1 ? item : `${item}s`

The solution is short and straightforward, because it's optimized for your specific use case – English pluratization.

Now, let's try to implement English pluratization using Intl.PluralRules. It's a JavaScript API, designed to support different languages and pluratization rules.

❌ The code becomes more complicated:

function pluralize(amount, item) {
  const suffixes = new Map([
    ['one',   item],
    ['other', item + 's'],
  const rules = new Intl.PluralRules('en-US');
  const rule = rules.select(amount);
  const suffix = suffixes.get(rule);
  return suffix;

See the difference? English-only code is easy to use. Reusable code is hard to use, because flexibility breeds complexity. This is the main idea of "The Use/Reuse Paradox":

What's easy to reuse is hard to use; what's easy to use is hard too reuse.

I recommend thinking about this principle for a while, because it's one of the most important principles of software architecture and design: with rare exceptions, simplicity and flexibility are opposing forces.

Alt Text

Agree/disagree? πŸ¦„

Posted on Dec 22 '19 by:

codingunicorn profile

Coding Unicorn πŸ¦„


Hi!✌(β—•β€Ώ-)✌ My name is Julia (also known as coding_unicorn on Instagram). I'm a full-stack developer specializing in Java and JavaScript.


markdown guide

Totally agree, especially for libraries it's hard, since you don't really know how they will be used. Ones sensible defaults might not me the same as ones others sensible default.

In the middle of adding functionality to a library now..