Don’t write code that is too DRY

// !!! multiple constants have the same value !!!
// This is not DRY
const MY_CONST_1 = "some value";
const MY_CONST_2 = "some value";
const MY_CONST_3 = "some value";
// !!! constants used only once !!!
// This extra layer of abstraction is not needed
const MY_CONST_COMPONENT_A = "a value only used in A";
const MY_CONST_COMPONENT_B = "a value only used in B";
const MY_CONST_COMPONENT_C = "a value only used in C";
  • A unit of code (class, variable, function, static method) used only once that is not in the same unit of code as its sole caller.
  • A unit of code that is obviously business related in a generic unit of code: e.g. a isShoppingCartEmpty function in a util.js file. Why isn’t this function in the ShoppingCart class?
  • A function that is just a big if/else where the conditional tests the presence of an argument:
function doSomething(arg1) {
if(!arg1) { // <-- this can indicate that the code was copy/pasted
// do something
} else {
// do almost the same thing, but with arg1
  • A one line function with a generic name that handles business logic
// misleading name
const isArrayEmpty = shoppingCart => shoppingCart.items.some(!tax);




Previously Paris and Geneva, currently New York. Can also be found at

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Store Objects and Arrays Using localStorage in JavaScript

How To Blur Objects in Real-Time With Video and Canvas

Adblockers Might Never Free the Web From Advertising

Quarkus in practice — Starting with Quarkus

Evolution of a Node.js API, Zoe.js — Layering

Making a resizable div in JS is not easy as you think

React : Social Media Integration with react-share and react-helmet.

Why I avoid async/await

Mark Twain

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arnaud Dostes

Arnaud Dostes

Previously Paris and Geneva, currently New York. Can also be found at

More from Medium

for(… in …) v/s for(… of ..)

GitHub Systematic Review: Know your data. | Simon Renger

Gmail filters for Software Engineers: Filtering recruiter inbounds

what’s my responsibility towards the web, anyway?