Urgent.News

What's breaking now, across thousands of outlets.

Tech

Don’t Build the Reusable Component Yet

Frontend developers often receive advice to create reusable components. While this can lead to cleaner code, it also increases coding and coordination costs. Duplication can be removed, but a poor abstraction can be costly to undo. The author recalls a situation where they had to perform three similar actions: item approval, item change, and item movement.

They created one component to address the similarities, but soon realized that the processes differed in important aspects such as handling partial failures, requirements for each process, and auditing information. They suggest waiting until the pattern of changes is repeated three times with the same reason for changing before abstracting.

Instead, they recommend grabbing the code and letting each screen evolve independently. The author cites the "Rule of Three" from Refactoring by Martin Fowler and The Wrong Abstraction by Sandi Metz, which suggest refactoring when a piece of code is encountered for the third time. They also reference Kent C. Dodds' AHA programming, which advises against hasty abstractions.

The author provides three criteria for determining when an abstraction is justified: the shape is determined by something other than speculation on the future, there is a single reason why it should be changed, and it is a component or workflow. They suggest starting by inlining the common module back into each call site, copying the module’s code to each workflow, and removing unnecessary branches.

Once the code is stabilized, they recommend separating it according to the workflow rather than layout. The author asks for clarification on what piece of code people often debate and what special flag they use for that specific caller.

Written by urgent.news from Stack Overflow Blog's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at stackoverflow.blog →

More in Tech

Map Shows How Data Center Measures Fared Across 10 States

Voters across 10 states largely rejected data center expansion, approving restrictions and bans in all but one ballot question.

  • Ohio had 21 data center measures, making approval challenging
  • 71% of Ohioans supported temporary ban on new data center construction
  • Illinois and California had opposing measures against data center development

Hackers steal US$112mil from French bank

PARIS: French lender Credit Mutuel Arkea said on Thursday hackers had stolen around €100 million (US$112.61 million) in a cyber heist and it was working to try to recover the money, in a rare case of…

More from Thursday 5 November →